Reputation: 37
I have following Sample table. table having combination of name and key column unique records
ID name key key_type
-----------------------------------
118 ab 12 aw1
119 fb 13 1Y2
120 cb 14 qw3
121 ab 15 4123
122 cs 12 23d2
select * from Sample where name ='ab' and key= '12'
select * from Sample where name ='fb' and key= '13'
how to write single query for both record ?
Upvotes: 0
Views: 92
Reputation: 9010
Easiest way would be
select *
from Sample
where (name = 'ab' and `key` = '12')
or (name = 'fb' and `key` = '13')
Demo here: http://sqlfiddle.com/#!9/3eabc/3
Throw an index on (name, key
) for good measure.
create index name_key on sample(name, `key`);
Upvotes: 0
Reputation: 44844
Easiest way would be union all
select * from Sample where name ='ab' and key= '12'
union all
select * from Sample where name ='fb' and key= '13'
Upvotes: 1