MySQL内部连接的查询也可以在关键字JOIN的帮助下编写。为了理解它,我们以两个名为tbl_1和tbl_2的表为例,它们具有以下数据:
Select * from tbl_1; +----+--------+ | Id | Name | +----+--------+ | 1 | Gaurav | | 2 | Rahul | | 3 | Raman | | 4 | Aarav | +----+--------+ 4 rows in set (0.00 sec) Select * from tbl_2; +----+---------+ | Id | Name | +----+---------+ | A | Aarav | | B | Mohan | | C | Jai | | D | Harshit | +----+---------+ 4 rows in set (0.00 sec)
现在,下面的查询将使用关键字JOIN内部联接表:
Select tbl_1.id,tbl_2.id FROM tbl_1 JOIN tbl_2 ON tbl_1.name = tbl_2.name; +----+----+ | id | id | +----+----+ | 4 | A | +----+----+ 1 row in set (0.00 sec)
在连接谓词上方的查询中,即条件写在ON关键字之后。