MySQL 仅从左联接的表中选择一些列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1329662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:58:05  来源:igfitidea点击:

Select only some columns from a table on a LEFT JOIN

mysqljoin

提问by Psyche

Is it possible to select only some columns from a table on a LEFT JOIN?

是否可以在 LEFT JOIN 的表中只选择一些列?

回答by VoteyDisciple

Of course. Just list the columns you want to select as you would in any query:

当然。只需像在任何查询中一样列出您要选择的列:

SELECT table1.column1, table1.column2, table2.column3
FROM table1
LEFT JOIN table2 ON (...)

Note that I've included the table1.or table2.prefix on all columns to be sure there aren't any ambiguities where fields with the same name exist in both tables.

请注意,我在所有列中都包含了table1.ortable2.前缀,以确保两个表中存在同名字段时不会有任何歧义。

回答by flayto

If you want some of table1's columns and some of table2's columns, you would do something like

如果你想要一些 table1 的列和一些 table2 的列,你会做类似的事情

SELECT t1.col1, t1.col2, t1.col3, t2.col1, t2.col2, t2.col3
FROM table1 t1
LEFT JOIN table2 t2
ON...

回答by jlansey

Add a *to just that table in your select statement, separate from other columns with a comma:

*在 select 语句中将a 添加到该表中,用逗号与其他列分开:

SELECT table1.*, table2.col2, table2.col3
FROM table1
LEFT JOIN table2
ON...

Source: https://stackoverflow.com/a/3492919/3417198

来源:https: //stackoverflow.com/a/3492919/3417198