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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple query on two columns

Status
Not open for further replies.

peterneve

Programmer
Jan 24, 2002
50
GB
Hi guys,

This should be a really simple problem.

I have a two column table set-up as follows.

Code:
w_id | file
123  | 100
234  | 101
123  | 102
456  | 100
678  | 104
678  | 100

What I want to to select the file that has w_id 123 AND w_id 678.

select * from table where w_id=123 AND w_id=678 doesn't work as no row meets such conditions, select * from table where w_id=123 OR w_id=678 doesn't work because severals files meet that condition.

Does anyone have any ideas.

Thanks :)
 
Code:
select file
from t
where w_id in (123,678)
group by file
having count(*) = 2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top