Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql select all for one table only

I have a couple joins that I'm doing. I say tablename.column to identify what I want to select in the database...don't want to select all columns. However, my last join I do want to select all for that. Is there a way I can use an asterisk or something for the last join?

The last table is going to be dynamic too so I can't hard code it in (although I could write it out dynamically) but thought there might be an easier way.

    SELECT content_name.name,
           house.listing,
           street.* 
      FROM content 
INNER JOIN house ON content_name.id=house.id 
 LEFT JOIN street ON content_name.id=street.id;
like image 236
Keith Avatar asked Jul 20 '10 18:07

Keith


1 Answers

Alias your last table the same way everytime, and then just .* your alias.

SELECT content_name.name,house.listing, last_table.* 
FROM content INNER JOIN house ON 
content_name.id=house.id 
LEFT JOIN street last_table ON content_name.id=last_table.id;

That being said, * in a production query is an accident waiting to happen.

like image 79
rfusca Avatar answered Oct 30 '22 07:10

rfusca