gpt4 book ai didi

mysql - 查询元数据键不存在的行

转载 作者:行者123 更新时间:2023-11-29 14:47:54 24 4
gpt4 key购买 nike

SELECT DISTINCT wposts.ID AS ID
FROM `wp_posts` AS wposts
JOIN `wp_postmeta` AS postmeta ON (wposts.ID = postmeta.post_id)
WHERE wposts.post_type = 'post'
AND wposts.ID NOT IN (
SELECT wp_posts.ID FROM wp_posts, `wp_postmeta` AS postmeta2
WHERE wp_posts.ID = postmeta2.post_id
AND postmeta2.meta_key = 'z_latitude'
)
ORDER BY wposts.post_date DESC

查询一团糟。我只是想查询没有特定元键的所有行。在上面,我查询了具有元键的所有行,然后将它们从外部查询中排除。我不知道如何写得更好。

最佳答案

通过左联接使用联接并抓取联接的行:

SELECT DISTINCT wposts.ID AS ID
FROM `doxy_posts` AS wposts
left JOIN `doxy_postmeta` AS postmeta ON wposts.ID = postmeta.post_id
WHERE postmeta.post_id is null
ORDER BY wposts.post_date DESC

关于mysql - 查询元数据键不存在的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6483228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com