MySQL 从一个表中选择所有列,从另一个表中选择一些列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3492904/
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 16:53:19  来源:igfitidea点击:

MySQL Select all columns from one table and some from another table

selectmysqljoin

提问by Alex

How do you select all the columns from one table and just some columns from another table using JOIN? In MySQL.

如何使用 JOIN 从一个表中选择所有列,而从另一个表中仅选择一些列?在 MySQL 中。

回答by Tatu Ulmanen

Just use the table name:

只需使用表名:

SELECT myTable.*, otherTable.foo, otherTable.bar...

That would select all columns from myTableand columns fooand barfrom otherTable.

这将选择所有列 frommyTable和 columnsfoobarfrom otherTable

回答by Simon

I need more information really but it will be along the lines of..

我真的需要更多信息,但它会沿着......

SELECT table1.*, table2.col1, table2.col3 FROM table1 JOIN table2 USING(id)

回答by Mzila

select a.* , b.Aa , b.Ab, b.Ac from table1 a left join table2 b on a.id=b.id

select a.* , b.Aa , b.Ab, b.Ac from table1 a left join table2 b on a.id=b.id

this should select all columns from table 1 and only the listed columns from table 2 joined by id.

这应该选择表 1 中的所有列,并且仅选择表 2 中通过 id 连接的列。

回答by Himanshu

Using alias for referencing the tables to get the columns from different tables after joining them.

使用别名来引用表以在加入它们后从不同的表中获取列。

Select tb1.*, tb2.col1, tb2.col2 from table1 tb1 JOIN table2 tb2 on tb1.Id = tb2.Id