当前位置: 动力学知识库 > 问答 > 编程问答 >

php - 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
分享给朋友:
您可能感兴趣的文章:
随机阅读: