嗨,我正在尝试显示 :table_templates_boxes 中存在但 :table_templates_boxes_to_pages 中不存在的数据,但我收到错误。请帮帮我
这是我的代码
SELECT
tb.id,
tb.code
FROM
mxp_templates_boxes tb,
mxp_templates_boxes_to_pages tbtp
WHERE templates_id = 3
AND tb.id NOT IN
(SELECT
templates_boxes_id
FROM
:table_templates_boxes_to_pages)
ORDER BY tbtp.sort_order
最佳答案
编辑 1:
i want only id of
mxp_templates_boxes
which are not present inmxp_templates_boxes_to_pages
but instead it's returning all id's ofmxp_templates_boxes
试试这个:
SELECT tb.id, tb.code
FROM mxp_templates_boxes tb
WHERE tb.templates_id = 3
AND tb.id NOT IN ( select distinct templates_boxes_id
from mxp_templates_boxes_to_pages )
示例 @ SQL Fiddle
<小时/>原始答案:
data which is present in
table_templates_boxes
but not present intable_templates_boxes_to_pages
您可以直接使用已经定义的表别名。
SELECT
tb.id,
tb.code
FROM
mxp_templates_boxes tb,
mxp_templates_boxes_to_pages tbtp
WHERE templates_id = 3
AND tb.id NOT IN ( tbtp.templates_boxes_id )
ORDER BY tbtp.sort_order
关于mysql - 您的 SQL 语法在“:table_templates_boxes_to_pages”附近有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22762442/