Reputation: 1194
I want to select a record from below table I have tried with this query
SELECT * FROM `wp_postmeta` WHERE meta_key = 'rating_average' and meta_key='rating_counter'
Which is not working.
if I select with this then working
SELECT * FROM `wp_postmeta` WHERE meta_key = 'rating_average'
I want both meta_key = 'rating_average' and meta_key='rating_counter'
Upvotes: 1
Views: 67
Reputation: 14669
Try IN Query:
`SELECT *
FROM `wp_postmeta`
WHERE meta_key IN ('rating_average','rating_counter')
Upvotes: 1
Reputation: 1443
You can achieve your desired output using below methods
1) Using OR
SELECT *
FROM `wp_postmeta`
WHERE meta_key = 'rating_average' OR meta_key='rating_counter';
2) Using IN
SELECT *
FROM `wp_postmeta`
WHERE meta_key IN ('rating_average', 'rating_counter');
3) Using UNION
SELECT *
FROM `wp_postmeta`
WHERE meta_key = 'rating_average'
UNION
SELECT *
FROM `wp_postmeta`
WHERE meta_key = 'rating_counter';
Upvotes: 1
Reputation: 1269563
You want OR
, but a more typical way of doing this uses IN
:
SELECT *
FROM `wp_postmeta`
WHERE meta_key IN ('rating_average', 'rating_counter');
Upvotes: 2