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

how can this query be written without a UNION clause?

Status
Not open for further replies.

yehong

Programmer
Sep 22, 2003
291
US
I have this query and I want to know if its possible to write it without a UNION clause.

select id from table_a
where
(name='Atlanta' And locations In ('1' ,'2','3') )
union
select id from table_a
where
(name='Los Angeles' And locations In ('11' ,'12','13')).

Basically I only want those ids who have records with name='Atlanta' and locations in 1,2,3 and name='Los Angeles' and locations in 11,12,13.

The above UNION query gives me the correct results but my requirement does not allow using a UNION clause. Thanks in advance.
 
I get more records than I should see. For example I have ID=1, that has Atlanta and 1,2,3 and Los Angeles and 11,12,13. If I use Or I am geeting ID 1 plus other ids who have Los Angeles and 11,12,13 only.
 
sorry. i noticed that you have used one extra () brackets to enclose whole Where clause. I tried with that and it seemed to bring back correct data. I am going to test more data with that. thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top