sql - Query where two columns are in the result of nested query -


i'm writing query this:

select * mytable x in (select x y) , xx in (select x y) 

values columns x , xx has in result of same query: select x y.

i think query invoked twice senseless. there other option can write query more efficiently? maybe temp table?

actually no, there isn't smarter way write (without visiting y twice) given x mytable.x , mytable.yy matches may not same row.

as alternative, exists form of query is

select * mytable exists (select * y a.x = y.x)   , exists (select * y a.xx = y.x) 

if y contains x values of 1,2,3,4,5, , x.x = 2 , x.xx = 4, both exist (on different records in y) , record mytable should shown in output.

edit: answer previously stated you rewrite using _exists_ clauses work faster _in_. martin has pointed out, not true (certainly not sql server 2005 , above). see links


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -