sql - Alternative to nested select statements -
i have following tables structure:
currently filtering users implemented pretty complex nested sql query (moreover automatically generated linq). looks approximately like:
select (select (select ( infinity here...))))
is there way simplify filtering process?
please, take account there different characteristic types. here sub-queries conditions samples:
... cv.text '%aaa%' , c.id = 5 ... cv.imageid not null , c.id = 10 ... cv.number > 5 , c.id = 33
etc...
will appreciate , ideas(change db structure, change technology, etc...), thanks!
as describing it, query should this
select u.id users u exists ( select * characteristicvalues cv cv.text '%aaa%' , cv.characteristicid = 5 , u.id = cv.userid ) , exists ( select * characteristicvalues cv cv.imageid not null , cv.characteristicid = 10 , u.id = cv.userid ) , exists ( select * characteristicvalues cv cv.number > 5 , cv.characteristicid = 33 , u.id = cv.userid )
or even
select distinct cv.userid characteristicvalues cv cv.text '%aaa%' , cv.characteristicid = 5 union select distinct cv.userid characteristicvalues cv cv.imageid not null , cv.characteristicid = 10 union select distinct cv.userid characteristicvalues cv cv.number > 5 , cv.characteristicid = 33
Comments
Post a Comment