Need to code a sql to filter records form a table based on combination conditions. show records if column_1 is "A" and then column_2 is "100" OR if column_1 is "B" and then column_2 is "200"
select *
from tableTmp
where
name="student"
and ((column_1="A" and column_2 = "100") OR (column_1="B" and column_2 = "200"))
when the first condition is not there, it will show what we want. but if there is first condition, then column_1="C" data still will show, the query is broken.
do you know why ?
Use single quotes for literals:
select *
from tableTmp
where name='student'
and (
(column_1='A' and column_2 = '100')
OR (column_1='B' and column_2 = '200')
)
However I cannot see how a column_1 value of 'C' can be returned by that query.
Nb. If column_2 is a numeric data type don't use single quotes.
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.