跟燕十八學習PHP 第二十七天 左右內連線的區別

2022-07-31 17:42:12 字數 4751 閱讀 5151

mysql> create table boy (

-> bname varchar(20),

-> other char(1)

-> )engine myisam charset utf8;

query ok, 0 rows affected (0.23 sec)

mysql>

mysql> insert into boy

-> values

-> ('屌絲','a'),

-> ('李四','b'),

-> ('王五','c'),

-> ('高富帥','d'),

-> ('鄭七','e');

query ok, 5 rows affected (0.02 sec)

records: 5 duplicates: 0 warnings: 0

mysql>

mysql>

mysql>

mysql> create table girl (

-> gname varchar(20),

-> other char(1)

-> )engine myisam charset utf8;

query ok, 0 rows affected (0.16 sec)

mysql>

mysql> insert into girl

-> values

-> ('空姐','b'),

-> ('大s','c'),

-> ('阿嬌','d'),

-> ('張柏芝','d'),

-> ('林黛玉','e'),

-> ('寶釵','f');

query ok, 6 rows affected (0.03 sec)

records: 6 duplicates: 0 warnings: 0

mysql> select * from boy;

+--------+-------+

| bname | other |

+--------+-------+

| 屌絲 | a |

| 李四 | b |

| 王五 | c |

| 高富帥 | d |

| 鄭七 | e |

+--------+-------+

5 rows in set (0.00 sec)

mysql> select * from girl;

+--------+-------+

| gname | other |

+--------+-------+

| 空姐 | b |

| 大s | c |

| 阿嬌 | d |

| 張柏芝 | d |

| 林黛玉 | e |

| 寶釵 | f |

+--------+-------+

6 rows in set (0.00 sec)

mysql> select boy.*,girl.* from

-> boy left join girl on boy.other=girl.other;

+--------+-------+--------+-------+

| bname | other | gname | other |

+--------+-------+--------+-------+

| 屌絲 | a | null | null |

| 李四 | b | 空姐 | b |

| 王五 | c | 大s | c |

| 高富帥 | d | 阿嬌 | d |

| 高富帥 | d | 張柏芝 | d |

| 鄭七 | e | 林黛玉 | e |

+--------+-------+--------+-------+

6 rows in set (0.00 sec)

mysql> #女生上台,帶著另一半,沒有另一半的,用null補齊

mysql> select boy.*,girl.* from

-> girl left join boy on boy.other=girl.other;

+--------+-------+--------+-------+

| bname | other | gname | other |

+--------+-------+--------+-------+

| 李四 | b | 空姐 | b |

| 王五 | c | 大s | c |

| 高富帥 | d | 阿嬌 | d |

| 高富帥 | d | 張柏芝 | d |

| 鄭七 | e | 林黛玉 | e |

| null | null | 寶釵 | f |

+--------+-------+--------+-------+

6 rows in set (0.00 sec)

mysql> #注意,a left join b,並不是說a表的就一定在左邊,只是說在查詢資料時,以a表為準

mysql> select * from boy;

+--------+-------+

| bname | other |

+--------+-------+

| 屌絲 | a |

| 李四 | b |

| 王五 | c |

| 高富帥 | d |

| 鄭七 | e |

+--------+-------+

5 rows in set (0.00 sec)

mysql> select other,bname from boy;

+-------+--------+

| other | bname |

+-------+--------+

| a | 屌絲 |

| b | 李四 |

| c | 王五 |

| d | 高富帥 |

| e | 鄭七 |

+-------+--------+

5 rows in set (0.00 sec)

mysql> #女生上台,帶著另一半,沒有另一半的,用null補齊

mysql> #不能用左連線來做

mysql> #用右連線. 剛才是 女生 left join 男

mysql> #用右連線,只需 男 right join 女

mysql> select boy.*,girl.*

-> from

-> boy right join girl

-> on boy.other = girl.other;

+--------+-------+--------+-------+

| bname | other | gname | other |

+--------+-------+--------+-------+

| 李四 | b | 空姐 | b |

| 王五 | c | 大s | c |

| 高富帥 | d | 阿嬌 | d |

| 高富帥 | d | 張柏芝 | d |

| 鄭七 | e | 林黛玉 | e |

| null | null | 寶釵 | f |

+--------+-------+--------+-------+

6 rows in set (0.01 sec)

mysql> select boy.*,girl.*

-> from

-> boy inner join girl

-> on boy.other=girl.other;

+--------+-------+--------+-------+

| bname | other | gname | other |

+--------+-------+--------+-------+

| 李四 | b | 空姐 | b |

| 王五 | c | 大s | c |

| 高富帥 | d | 阿嬌 | d |

| 高富帥 | d | 張柏芝 | d |

| 鄭七 | e | 林黛玉 | e |

+--------+-------+--------+-------+

5 rows in set (0.00 sec)

mysql> exit

第二十七天

今天主要學習了linux的程序通訊 程序通訊可分為 管道通訊 訊號通訊 共享記憶體和訊息佇列 管道通訊 分無名管道和有名管道,無名管道一般用於父子程序之間 訊號通訊的產生方式 1.按鍵產生 2.硬體異常產生 除數為0,無效儲存訪問等 3.程序用kill函式給另乙個程序發訊號 4.使用者用kill命令...

學習第二十七天

一 this關鍵字 this關鍵字 this動態繫結物件 1 this所在的函式是否是通過new呼叫使用的,如果是指向當前new的物件 2 this是通過物件.函式名 使用,this指代當前呼叫的物件 3 this預設指代window,window指全域性物件 定義的全域性變數,預設定義window...

學習python 第二十七天

python生成 import xlwt def export excel request 建立乙個workbook 設定編碼 workbook xlwt.workbook encoding utf 8 新增工作表 工作表名,這個引數是可選的,預設建立的工作表 sheet workbook add ...