Reputation: 502
Can I, and if so, how do I prevent mysql from returning duplicate results
SELECT meta_id, post_id, DISTINCT meta_value FROM wp_postmeta WHERE post_id='69' AND meta_value LIKE '%iframe%'
I want to get just the one row, so ignore any further items if meta_value duplicated!
Putting DISTINCT where it is, returns no results, but query works as expected if removed, so it is obviously wrong to put it there!
Upvotes: 0
Views: 47
Reputation: 121
If you want only one result you can use LIMIT in MySql like
SELECT meta_id, post_id, DISTINCT meta_value
FROM wp_postmeta
WHERE post_id='69'
AND meta_value LIKE '%iframe%'
LIMIT 1
OR in Sql you can use
SELECT TOP 1 meta_id, post_id, DISTINCT meta_value
FROM wp_postmeta
WHERE post_id='69'
AND meta_value LIKE '%iframe%'
Upvotes: 1