交叉連接的MySQL查詢也可以藉助關鍵字JOIN來寫。為了理解它,我們以名為tbl_1 和tbl_2 的兩個表為例,它們具有以下資料:
mysql> Select * from tbl_1; +----+--------+ | Id | Name | +----+--------+ | 1 | Gaurav | | 2 | Rahul | | 3 | Raman | | 4 | Aarav | +----+--------+ 4 rows in set (0.00 sec) mysql> Select * from tbl_2; +----+---------+ | Id | Name | +----+---------+ | A | Aarav | | B | Mohan | | C | Jai | | D | Harshit | +----+---------+ 4 rows in set (0.00 sec)
現在,下面的查詢將使用關鍵字JOIN 交叉連接表:
mysql> Select tbl_1.id,tbl_2.id FROM tbl_1 JOIN tbl_2; +----+----+ | id | id | +----+----+ | 1 | A | | 2 | A | | 3 | A | | 4 | A | | 1 | B | | 2 | B | | 3 | B | | 4 | B | | 1 | C | | 2 | C | | 3 | C | | 4 | C | | 1 | D | | 2 | D | | 3 | D | | 4 | D | +----+----+ 16 rows in set (0.00 sec)
以上是如何借助關鍵字 JOIN 編寫 MySQL 交叉連接查詢?的詳細內容。更多資訊請關注PHP中文網其他相關文章!