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!

Question about a query

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
Hello all, I was wondering how do to something. I have a table that I need to do some kind of sub query. I am learning so this query eill teach me a lot. I have 2 columns One is the ID and the other is Num. I need to search for all Nums that have a "0" in it and get the ID of that row. I then need to search in the column "Num" and get match the row id. I think this would be an embedded search (something like that).

Here is my columns.
Code:
ID 	Num
2 	0 	
3 	2 	
4 	2
I will attempt the query string:
Code:
select Num from table where Num = (select ID from Num where Num = 0 )
Something like that. I want to learn how to do this kind of search.

Thanks,
timgerr

-How important does a person have to be before they are considered assassinated instead of just murdered?
Congratulations!
 
select b.num
from table a
inner join table b
on a.id = b.num
where a.num = 0

NOT TESTED!!!
 
select Num from table where Num = (select ID from Num where Num = 0 )
I guess you meant this:
Code:
select [!]ID[/!] from table where Num [!]IN[/!] (select ID from [!]table[/!] where Num = 0 )

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
select Num from table where Num = (select ID from Num where Num = 0 )

in this case the sub query should result a single ID.(according to query)



select ID from table where Num IN (select ID from table where Num = 0 )

in this case the sub query should result multiple IDs.
(So it works fine)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top