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 and & or

Status
Not open for further replies.

jjpetrucelli

Programmer
Dec 5, 2003
99
US
i have a query that goes a little something like this;

SELECT t.id, t.name, ts.id1, ts.id2, ts.test_name, e.id3
FROM table t, table b, table ts, table e
WHERE t.id = b.id
AND b.id1 = ts.id1
AND b.id = e.id
AND b.id1 = e.id1

so thats ok but i need to add onto the end of it something that says 'the query also needs to meet this criteria;'
e.flag in ('2', '3') and e.flag1 = '1'
'or it can meet this criteria;'
e.flag in ('1', '2', '3') and e.flag1 = '3'

im getting a little caught up with this, ive tried just saying;
and e.flag in ('2', '3') and e.flag1 = '1'
or e.flag in ('1', '2', '3') and e.flag1 = '3'

Ive also tried several scenarios with ( ) but it just takes forever and brings back nothing!
 
Have you tried this ?
SELECT t.id, t.name, ts.id1, ts.id2, ts.tribal_site_name, e.id3
FROM table t, table b, table ts, table e
WHERE t.id = b.id
AND b.id1 = ts.id1
AND b.id = e.id
AND b.id1 = e.id1
and ((e.flag in ('2', '3') and e.flag1 = '1')
or (e.flag in ('1', '2', '3') and e.flag1 = '3'))


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top