<span >FROM 表1 <span >INNER<span >|left|RIGHT <span >JOIN<span > 表2
<span >ON 表1.字段 <span >= 表2.字段; (<span >create <span >table<span > employee(
ID <span >int <span >primary <span >key<span > auto_increment,name <span >varchar(<span >20<span >),sex enum(<span >'<span >male<span >',<span >'<span >female<span >') <span >not <span >null <span >default <span >'<span >male<span >'<span >,age <span >int<span >,dep_ID <span >int<span >
);插入数据
<span >insert <span >into department <span >values<span >
(<span >200,<span >'<span >技术<span >'<span >),(<span >201,<span >'<span >人力资源<span >'<span >),(<span >202,<span >'<span >销售<span >'<span >),(<span >203,<span >'<span >运营<span >'<span >);
<span >insert <span >into employee(name,sex,age,dep_ID) <span >values<span >
(<span >'<span >egon<span >',<span >'<span >male<span >',<span >18,<span >200<span >),(<span >'<span >alex<span >',<span >'<span >female<span >',<span >48,<span >201<span >),(<span >'<span >wupeiqi<span >',<span >38,(<span >'<span >yuanhao<span >',<span >28,<span >202<span >),(<span >'<span >liwenzhou<span >',(<span >'<span >jingliyang<span >',<span >204<span >)
;
MysqL<span >> <span >desc<span > department;
<span >+<span >--<span >-----+-------------+------+-----+---------+-------+
<span >| FIEld <span >| Type <span >| <span >Null <span >| <span >Key <span >| <span >Default <span >| Extra <span >|
<span >+<span >--<span >-----+-------------+------+-----+---------+-------+
<span >| ID <span >| <span >int(<span >11) <span >| YES <span >| <span >| <span >NulL <span >| <span >|
<span >| name <span >| <span >varchar(<span >20) <span >| YES <span >| <span >| <span >NulL <span >| <span >|
<span >+<span >--<span >-----+-------------+------+-----+---------+-------+
<span >
MysqL<span >> <span >desc<span > employee;
<span >+<span >--<span >------+-----------------------+------+-----+---------+----------------+
<span >| FIEld <span >| Type <span >| <span >Null <span >| <span >Key <span >| <span >Default <span >| Extra <span >|
<span >+<span >--<span >------+-----------------------+------+-----+---------+----------------+
<span >| ID <span >| <span >int(<span >11) <span >| NO <span >| PRI <span >| <span >NulL <span >| auto_increment <span >|
<span >| name <span >| <span >varchar(<span >20) <span >| YES <span >| <span >| <span >NulL <span >| <span >|
<span >| sex <span >| enum(<span >'<span >male<span >',<span >'<span >female<span >') <span >| NO <span >| <span >| male <span >| <span >|
<span >| age <span >| <span >int(<span >11) <span >| YES <span >| <span >| <span >NulL <span >| <span >|
<span >| dep_ID <span >| <span >int(<span >11) <span >| YES <span >| <span >| <span >NulL <span >| <span >|
<span >+<span >--<span >------+-----------------------+------+-----+---------+----------------+
<span >
MysqL<span >> <span >select <span > <span >from<span > department;
<span >+<span >--<span >----+--------------+
<span >| ID <span >| name <span >|
<span >+<span >--<span >----+--------------+
<span >| <span >200 <span >| 技术 <span >|
<span >| <span >201 <span >| 人力资源 <span >|
<span >| <span >202 <span >| 销售 <span >|
<span >| <span >203 <span >| 运营 <span >|
<span >+<span >--<span >----+--------------+
<span >
MysqL<span >> <span >select <span > <span >from<span > employee;
<span >+<span >--<span >--+------------+--------+------+--------+
<span >| ID <span >| name <span >| sex <span >| age <span >| dep_ID <span >|
<span >+<span >--<span >--+------------+--------+------+--------+
<span >| <span >1 <span >| egon <span >| male <span >| <span >18 <span >| <span >200 <span >|
<span >| <span >2 <span >| alex <span >| female <span >| <span >48 <span >| <span >201 <span >|
<span >| <span >3 <span >| wupeiqi <span >| male <span >| <span >38 <span >| <span >201 <span >|
<span >| <span >4 <span >| yuanhao <span >| female <span >| <span >28 <span >| <span >202 <span >|
<span >| <span >5 <span >| liwenzhou <span >| male <span >| <span >18 <span >| <span >200 <span >|
<span >| <span >6 <span >| jingliyang <span >| female <span >| <span >18 <span >| <span >204 <span >|
<span >+<span >--<span >--+------------+--------+------+--------+
1 交叉连接:不适用任何匹配条件。生成笛卡尔积
MysqL ID name sex age dep_ID ID name egon male 技术 egon male 人力资源 egon male 销售 egon male 运营 alex female 技术 alex female 人力资源 alex female 销售 alex female 运营 wupeiqi male 技术 wupeiqi male 人力资源 wupeiqi male 销售 wupeiqi male 运营 yuanhao female 技术 yuanhao female 人力资源 yuanhao female 销售 yuanhao female 运营 liwenzhou male 技术 liwenzhou male 人力资源 liwenzhou male 销售