简体   繁体   English

MYSQL从两个不同表的列中不存在id的表中检索数据

[英]MYSQL Retrieving data from a table where id is not present in a column of two differents tables

What is the right syntax for something like this: 像这样的正确语法是什么:

SELECT * FROM gals 
WHERE id NOT IN (SELECT id_gal FROM paginas_principales)
     AND id NOT IN (SELECT id_gal FROM paginas_secundarias)

I'll appreciate any help. 我将不胜感激。

Must be: 一定是:

SELECT * FROM gals 
WHERE id NOT IN (SELECT id_gal FROM paginas_principales)
     AND id NOT IN (SELECT id_gal FROM paginas_secundarias) ORDER BY id DESC
         ^^^^
SELECT * FROM gal LEFT JOIN primary ON gal.id_gal = primary.id_gal LEFT JOIN secondary ON gal.id_gal = secondary.id_gal WHERE primary.id_gal IS NULL AND secondary.id_gal IS NULL

Try this: 尝试这个:

SELECT * FROM gals g,(SELECT id_gal FROM paginas_principales)t 
WHERE g.id !=t.id_gal 
     AND g.$whateveryourcolumn !=t.id_gal ORDER BY id DESC

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SELECT 来自两个表 WHERE 每个表中的不同列等于 $id ORDER BY 公共列(PHP / MySQL) - SELECT from two tables WHERE different columns in each table equal $id ORDER BY common column (PHP/MySQL) 从两个mysql表中检索数据 - Retrieving data from two tables of mysql 从两个mysql表中选择,它们的列值相似并且id从上一页检索 - select from two mysql tables where column value is similar and id is retrieved from previous page 联接3个MySQL表时遇到问题,无法从两个表中检索数据(CodeIgniter) - Having trouble JOINing 3 MySQL tables, retrieving data from two (CodeIgniter) 从两个具有ID的表中检索数据,并在Mysql中显示另一个表的最大ID - Retrieve data from two tables having id and display the max id of another table in Mysql 一次从两个表中检索数据,一个表引用另一个表 - Retrieving data from two tables at once with one table referencing the other PHP MySQL“从`table` WHERE`id` = |未知列`id`中删除 - PHP MySQL "DELETE FROM `table` WHERE `id` = | unknown column `id` 检索存在特定user_id的所有行的数据? - Retrieving data all rows where specific user_id is present? PHP MySQL:从表A获取行,其中表B的Z列中不存在表A的Z列的值 - PHP MySQL: Getting rows from table A where values of column Z of Table A not present in column Z of table B 从两个mysql表中获取数据,其中一个表的行与另一个表的行连接 - Get data from two mysql tables, where row of one table is connected to many in other
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM