MySQL FROM子句用于从表中选择一些记录。它还可以用于使用JOIN条件从多个表中检索记录。
语法:
FROM table1 [ { INNER JOIN | LEFT [OUTER] JOIN| RIGHT [OUTER] JOIN } table2 ON table1.column1 = table2.column1 ]
table1和table2 - 指定MySQL语句中使用的表。这两个表基于table1.column1 = table2.column1连接。
注意:
以下查询指定如何从单个表中检索数据。
SELECT * FROM officers WHERE officer_id
让无涯教程以使用INNER JOIN从两个表中检索数据为例。在这里,有两个表"officers"和"students"。
执行以下查询:
SELECT officers.officer_id, students.student_name FROM students INNER JOIN officers ON students.student_id = officers.officer_id;
执行以下查询:
SELECT officers.officer_id, students.student_name FROM officers LEFT OUTER JOIN students ON officers.officer_id = students.student_id;
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)