I would like to query a table, where i need 2 columns meet certain criteria, as an example, a table like below:
LastName FirstName Age address
LN1 FN1 18 ADD1
LN2 FN1 20 ADD2
Now I want to extract 1st address like below:
select * from mytable
where LastName in 'LN1' and FirstName in 'FN1'
Can I use such a condition:
where (LastName, FirstName) in (LN1,FN1)
please kindly help. thanks.
答案 0 :(得分:2)
Some databases support the syntax you want:
where (LastName, FirstName) in ('LN1', 'FN1')
Note that the single quotes are important, because they are string constants.
In other databases, you need to do:
where LastName = 'LN1' or FirstName = 'FN1'
or perhaps put the constants into a derived table, and use a join
for the matching.
答案 1 :(得分:0)
You can either use or
or and
select * from mytable where LastName = 'LN1' or FirstName = 'FN1';
select * from mytable where LastName = 'LN1' and FirstName = 'FN1';