简体   繁体   中英

SQL statement with multiple Or and And conditions

i have a problem i cant find the solution right now.

here is an example sql statement of my kind:

SELECT * FROM table
WHERE ((id IS '2' AND name IS 'foo' ) OR 
   (is IS '3' AND name IS 'bar' ) OR 
   (id IS '4' AND name IS 'foobar'))

for any reason it only returns one row but it should return all 3 rows.

EDIT:

I found my error and it was nothing but stupidness of mine. sorry for your inconvenience.....

in my real statement all ORd clauses where equal and i couldnt see the tree for the forest..

I'd almost say the problem is in your data, but you're not giving us enough info. Check your table and make sure you're querying appropriately. Based on your statement, your query should work (with corrected fixes). Look at the sqlfiddle linke here.

You should use standard SQL syntax wherever possible.

SELECT * FROM table

ID    NAME
==    ====
1     boo
2     foo
3     bar
4     foobar

SELECT 
  * 
FROM 
  table
WHERE 
  (id = '2' AND name = 'foo' ) OR 
  (id = '3' AND name = 'bar' ) OR 
  (id = '4' AND name = 'foobar')

ID    NAME
==    ====
2     foo
3     bar
4     foobar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM