mysql - Result of nested SQL statements in WHERE clause -


i have table of beats , each beat there multiple rows containing different prices in pricing table.

select b.id, b.name, (select p.price pricing p p.license = 1 , p.beat_id = b.id) price_1, (select p.price pricing p p.license = 2 , p.beat_id = b.id) price_2 beats b  b.added > 0  , b.active = 1  , b.deleted = 0  , price_1 > 0 order b.id desc  limit 50 

i'm trying make sure beat retrieved when price_1 greater 0.

this doesn't work because can't use result of nested sql statement in where clause, i've tried having price_1 > 0 , doesn't work either.

how can test price_1 , price_2?

you can move condition having clause. feature of mysql , not supported other databases:

select b.id, b.name,        (select p.price pricing p p.license = 1 , p.beat_id = b.id) price_1,        (select p.price pricing p p.license = 2 , p.beat_id = b.id) price_2 beats b  b.added > 0 , b.active = 1 , b.deleted = 0  group b.producer  having price_1 > 0 order b.id desc  limit 50; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -