dongyi7513 2014-03-12 18:27 采纳率: 100%
浏览 9

MySQL:选择两个表之间不常见的数据

I have table1 with 3 numbers and table2 with 1 number:

table1       table2
n              n
1              1
2
3

I want to select data from table1 that is NOT present in table2 (numbes 2 and 3). I tried:

select table1.* from table1, table2 where table1.n <> table2.n

I also tried other where clauses:

where table1.n not like table2.n
where not table1.n = table2.n

But I don't get the results. I know it can be done in multiple steps, but I wonder if there is a simple query to do it. Thanks

  • 写回答

3条回答 默认 最新

  • dongtuo3530 2014-03-12 18:29
    关注

    You can do that using NOT IN or NOT EXISTS.

    select * from table1
    where table1.n not in (select table2.n from table2);
    
    select * from table1
    where  not exists (select table2.n from table2 where table2.n = table1.n);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题