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

SelectMysqlJoin

Select Problem Overview


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

Select Solutions


Solution 1 - Select

Just use the table name:

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

That would select all columns from myTable and columns foo and bar from otherTable.

Solution 2 - Select

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)

Solution 3 - Select

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.

Solution 4 - Select

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexView Question on Stackoverflow
Solution 1 - SelectTatu UlmanenView Answer on Stackoverflow
Solution 2 - SelectSimonView Answer on Stackoverflow
Solution 3 - SelectMzilaView Answer on Stackoverflow
Solution 4 - SelectHimanshuView Answer on Stackoverflow