Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return ALL columns in one table and just a few in another using join?

Tags:

sql

I would rather not have to list all columns in tableA The '*' works for one table, but I don't want to get back all columns in tableB from JOIN. Reason being, these records are being deleted, and I want to store data from tableA (only) as serialized xml for period of time.

like image 878
john pavelka Avatar asked Aug 02 '10 14:08

john pavelka


2 Answers

select tableA.*, tableB.col1, tableB.col2, ...
like image 175
kennytm Avatar answered Oct 11 '22 19:10

kennytm


It is a poor practice to ever use select * or select table1.*. It is bad for maintenance and performance both. You should never do that in production code.

Just use the column names that you want.

like image 34
HLGEM Avatar answered Oct 11 '22 19:10

HLGEM