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

标签 mysql

嗨,我正在尝试显示 :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/

相关文章:

mysql - 格式日期从 2017 年 5 月 17 日星期三到 17/05/2017 SQL 格式

如果为 NULL,MySQL 更新/连接列,使用来自其他列的数据

mysql - 使用docker-compose无法在同一网络中连接mysql和spring boot

mysql - 获取所有具有不同用户 ID 并按总分排序

mysql - 如何理解 MySQL 中组合主数据库的基数

mysql - 安装redmine后出现"There was an error while trying to load the gem ' mysql2 '. (Bundler::GemRequireError)"错误

php - MySQL选择查询,连接并转换为日期两个字段并与时间间隔进行比较

MySQL:优化无主键的表(索引、外键)

python - 为 python 3.5.2 安装 MySql

php - 无法使用 html 和 php 更新 mysql 中的值