zoukankan      html  css  js  c++  java
  • SQL_left join 和from 两个表的区别

    一个是普通的联接,结果中的记录在两个表中都有。
    一个是左外联接,结果中的记录在A表中存在,B表中不一定有。相当于a表为主体表,b为辅助表。

    例子:

    mysql> select * from a;
    +------+------+
    | id | col |
    +------+------+
    | 1 | 11 |
    | 2 | 12 |
    | 3 | 13 |
    +------+------+
    3 rows in set (0.00 sec)

    mysql> select * from b;
    +------+------+
    | id | col |
    +------+------+
    | 2 | 22 |
    | 3 | 23 |
    | 5 | 25 |
    +------+------+
    3 rows in set (0.00 sec)

    mysql>
    mysql> select * from a,b where a.id=b.id;
    +------+------+------+------+
    | id | col | id1   | col1  |
    +------+------+------+------+
    | 2 | 12 | 2 | 22 |
    | 3 | 13 | 3 | 23 |
    +------+------+------+------+
    2 rows in set (0.08 sec)

    mysql> select * from a left join b on a.id=b.id;
    +------+------+------+------+
    | id | col | id1   | col1  |
    +------+------+------+------+
    | 1 | 11 | NULL | NULL |
    | 2 | 12 | 2 | 22 |
    | 3 | 13 | 3 | 23 |
    +------+------+------+------+
    3 rows in set (0.00 sec)

    mysql>

  • 相关阅读:
    2-SAT·hihoCoder音乐节
    Music in Car
    Game with a Strip
    Oleg and Little Ponies
    组合数性质求K个数选取i*j个数分成j组的方案数
    Python学习笔记03
    Python学习笔记02
    Python 学习笔记01
    欺骗侦测
    Oracle 使用小计(4)
  • 原文地址:https://www.cnblogs.com/flzs/p/13595062.html
Copyright © 2011-2022 走看看