Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL sub-query troubles

Status
Not open for further replies.

USX01

Programmer
Aug 15, 2006
4
US
I have stared at this for a while to no avail. I'm not sure why this isn't working,the errror i'm getting is a "invalid sql statement" error. Here's the rough SQL statement:

select A, B
from X
where A,B in (select Y,Z
from C
where ....)

Thanks inadvance
 
I believe you need:

Code:
SELECT
    A,
    B
FROM
    X
WHERE
    (A, B) in (SELECT A, B FROM C WHERE)

--Rob
 
Thanks Rob, however in the where clause

WHERE
(A, B) in (SELECT A, B FROM C WHERE)

NEED TO BE:

SELECT
A,
B
FROM
X
WHERE
(A, B) in (SELECT Y,Z FROM C WHERE)
 
USX,

As an alternative and a performance comparison, try:
Code:
SELECT A,B
FROM X
WHERE exists (select 'foo' from C
               WHERE x.a = Y
                 and x.b = Z);
This construction typically performs much faster, producing the same results.

Let us know your findings.


[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top