Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - Left Join, Select all columns left, few columns on the right tables,

I'm trying to join two tables together as shown below, in the " * " section, I'm having trouble doing the following,

Operation: want to select all columns on the left, and just wanna attach few relevant columns from the right table to the left table. Instead of writing all the columns like left_table.column1, left_table.column2 ... so on is there another method which saves the manual coding?

SELECT * FROM nutrients LEFT JOIN measures ON nutrients.name=measures.name
like image 463
lukieleetronic Avatar asked Dec 20 '14 07:12

lukieleetronic


1 Answers

Yes, add the table name before the * to select all columns of a table

SELECT nutrients.*, measures.colX
FROM nutrients 
LEFT JOIN measures ON nutrients.name=measures.name
like image 103
juergen d Avatar answered Oct 21 '22 15:10

juergen d