zoukankan      html  css  js  c++  java
  • mysql中两张表使用left join on 求差集

    1.表结构

    mysql> select * from allStudents;
    +----+-------+
    | id | name  |
    +----+-------+
    |  1 | ????  |
    |  2 | ????  |
    |  3 | ???·   
    |  4 | four  |
    +----+-------+
    4 rows in set (0.00 sec)
    
    mysql> select * from currentStudents;
    +----+--------+
    | id | name   |
    +----+--------+
    |  1 | luowen |
    |  3 | 毛毛想 |
    +----+--------+
    

    2.子查询方法

    mysql> select * from test where test.id not in ( select id from user);
    +----+----------+--------+
    | id | name     | salary |
    +----+----------+--------+
    |  2 | 脙芦脙芦     |   4000 |
    |  4 | four     |  23232 |
    +----+----------+--------+
    

    3.left join 方法

    mysql> select allStudents.*,currentStudents.* from allStudents,currentStudents where allStudents.id = currentStudents.id;
    +----+-------+----+---------+
    | id | name  | id |    name |
    +----+-------+----+---------+
    |  1 | ????  |  1 | luowen  |
    |  3 | ???·  |  3 | 毛毛想  |
    +----+-------+----+---------+
    2 rows in set (0.00 sec)
    
    mysql> select allStudents.*,currentStudents.* from allStudents left join currentStudents on allStudents.id = currentStudents.id;
    +----+-------+------+------------+
    | id | name  | id   | name       |
    +----+-------+------+------------+
    |  1 | ????  |    1 | luowen     |
    |  2 | ????  | NULL | NULL       |
    |  3 | ???·  |    3 | 毛毛想     |
    |  4 | four  | NULL | NULL       |
    +----+-------++------+-----------+
    4 rows in set (0.00 sec)
    
    mysql> select allStudents.*,currentStudents.* from allStudents left join currentStudents on allStudents.id = currentStudents.id where currentStudents.id is null;
    +----+------+------+----------+
    | id | name | id   | name     |
    +----+------+------+----------+
    |  2 | ???? | NULL | NULL     |
    |  4 | four | NULL | NULL     |
    +----+------+------+----------+
    2 rows in set (0.00 sec)
    

      

  • 相关阅读:
    Shell中调用java时的参数
    简析echo命令在Linux系统中的使用
    设置Linux环境变量的三种方法
    nohup 后台运行,以及重定向标准输出和标准错误 &/dev/null 文件
    &命令
    linux下卸载gij的java
    在Linux下运行可执行Jar包
    jar参数运行应用时classpath的设置方法
    shell获取当前进程pid和上一个进程pid
    检查文件,如果文件不存在则创建
  • 原文地址:https://www.cnblogs.com/luowen/p/3548719.html
Copyright © 2011-2022 走看看