1

My db table is as follows

testTable

|-----|-------------------|
  Id     comment
   2  | 20 degree celsius
   3  | 30 degree Farenheit
   4  | 40 degree Farenheit
   5  | sometime 
   6  | plain text
   7  | plain text
   8  | plain text

I want to query the db to get all the ids where string contains celsius or farenheit

Query :

SELECT Id FROM testTable where id in (2,3,4) 
AND comment like '%celsius%' or comment like '%Farenheit%'

but this query checks for all the ids not the id I provide in the in condition ? How to query for only the id in the in Condition ?

4

1 回答 1

8

只需使用这样的括号:

SELECT Id FROM testTable where id in (2,3,4) 
AND 
(comment like '%celsius%' or comment like '%Farenheit%')

看到这个 SQLFiddle

于 2013-08-20T07:11:46.073 回答