Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

join

select

mysql

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

like image 243
Alex Avatar asked Aug 16 '10 12:08

Alex


People also ask

How do I SELECT all columns except one column from a table in MySQL?

A MySQL SELECT statement is used to retrieve data from a MySQL table. To exclude certain column(s) from the SELECT statement result, you can omit the column/ field name from the query.


2 Answers

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.

like image 156
Tatu Ulmanen Avatar answered Sep 20 '22 11:09

Tatu Ulmanen


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) 
like image 24
Simon Avatar answered Sep 20 '22 11:09

Simon