是否可以在左连接表中指定您想要的字段
IE
SELECT * FROM students
LEFT OUTER JOIN classes_enrolled (can i specify fields here)
ON students.student_id = classes_enrolled.student_id
我只想从左连接表classes_enrolled中获取字段主题,而不是附加匹配行中的所有字段
为什么不尝试类似的东西
SELECT students.* ,
classes_enrolled.subject
FROM students LEFT OUTER JOIN
classes_enrolled ON students.student_id = classes_enrolled.student_id
实际上,指定字段名称而不是使用SELECT *
您可以选择以下任何一项:
使用子查询在指定列上进行选择,
SELECT *
FROM students
LEFT OUTER JOIN
(
SELECT student_id, subject
FROM classes_enrolled
) b ON students.student_id = b.student_id
或者我更喜欢的——手动选择这些列,
SELECT students.*,
classes_enrolled.subject
FROM students
LEFT OUTER JOIN classes_enrolled
ON students.student_id = classes_enrolled.student_id
试试下面的 SELECT , classes_enrolled.subject, * FROM students, LEFT OUTER JOIN classes_enrolled ON students.student_id = classes_enrolled.student_id