gpt4 book ai didi

mysql - 您的 SQL 语法在“:table_templates_boxes_to_pages”附近有错误

转载 作者:行者123 更新时间:2023-11-30 00:27:25 25 4
gpt4 key购买 nike

嗨,我正在尝试显示 :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 in mxp_templates_boxes_to_pages but instead it's returning all id's of mxp_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 in 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 ( tbtp.templates_boxes_id )
ORDER BY tbtp.sort_order

关于mysql - 您的 SQL 语法在“:table_templates_boxes_to_pages”附近有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22762442/

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