我无法想象如何构建查询。我需要从表 CONTENT
中选择行 hasnot column tmplvarid=8 in left joined TEMPLATE VARIABLES
column
SELECT con.id, con.alias, tv.tmplvarid FROM modx_site_content as con 左连接 modx_site_tmplvar_contentvalues as tv ON con.id=tv.contentid WHERE con.deleted=0 AND (con.content IS NULL OR con .content='') AND con.template=5 AND tv.tmplvarid!=8/*不包含 8*/
最佳答案
简单:不要执行INNER 联接,而是执行OUTER JOIN:
SELECT con.id, con.alias, tv.tmplvarid FROM modx_site_content as con
LEFT OUTER JOIN modx_site_tmplvar_contentvalues as tv ON con.id=tv.contentid
AND tv.templvarid = 8
WHERE con.deleted=0 AND (con.content IS NULL OR con.content='')
AND con.template=5 AND tv.contentid IS NULL
因此您在 OUTER JOIN 中加入 templvarid = 8 - 然后仅选择(在其中)在 tv 中具有 NULL 的行。 contentid(那是那些找不到用于加入的 templvarid 8 的)
关于mysql - 如果连接表中存在指定值,如何使用 LEFT JOIN 选择行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44393126/