我查询了表格中的节目数据
SELECT DISTINCT t1.ID AS postid, t2.meta_value AS sku, t1.post_date AS DATE, t1.post_content AS content, t1.post_title AS title
FROM wp_posts t1, wp_postmeta t2
WHERE t1.ID = t2.post_id
AND t2.meta_key = '_sku'
我如何只显示重复的meta_values。我的意思是这个选择中的所有重复记录 - 我发现解决方案只显示一次重复的_sku?
Postid | sku | ..
111 | xxx | ...
222 | xxx | ...
333 | xxx | ...
444 | xxx | ...
谢谢!
答案 0 :(得分:1)
您可以使用以下内容扩展您的where子句:
AND t2.meta_value IN (SELECT meta_value FROM wp_postmeta GROUP BY meta_value HAVING COUNT(meta_value) > 1)
警告:我目前无法访问MySQL数据库,所以这是Trnas-SQL语法,如果不相同则应该相似