By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,856 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,856 IT Pros & Developers. It's quick & easy.

Are sub-subqueries possible?

P: n/a
Hi all,

I've seen mention that you can use nested subqueries down to as many
levels as you like but whenever I run the following:

select * from table1
where tab1ID in
(select tab1ID from table2 where tab2ID in
(select tab2ID from Table3 where Tab3ID=N))

I get the error "incorrect syntax near the keyword 'where'"

Can anyone confirm that sub-subqueries are possible? If so is the
syntax I'm using correct?

I'm running SQL 2000 through a Delphi 5 app.


Apr 12 '06 #1
Share this Question
Share on Google+
2 Replies

P: n/a
yes look at this example in the pubs DB

use pubs
select * from authors
where au_id in(select au_id from authors where au_id in( select au_id
from authors where au_id ='172-32-1176'))

You can also write your query as follows
select t1.* from table1 t1
join table2 on t1.tab1ID =t2.tab1ID
join Table3 t3 on t3.tab2ID =t2.tab2ID
where t3.Tab3ID=N --this should be 'N' or a number probably ???
Denis the SQL Menace

Apr 12 '06 #2

P: n/a
Thanks Denis

yeah I just installed Query Analyser & ran my query through that & it
worked fine so it must be a limitation of the Delphi TQuery component.

Oh well.

I'll try a join as you suggested instead.

Thanks for your time

Apr 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.