I have a sql query that joins 2 tables on the column product_id
. Pretty straight forward. Result is below:
However, after joining, I realized I have to do a subquery with all the columns listed here. I obviously need to remove or alias one of the product_id
columns to prevent ambiguity. Since this is a small table, its not that bad in terms of efficiency to just SELECT
the relevant columns (7 total). However, this led to me wondering, what if I had 2 giant production-level tables with 100 columns each? It would be incredibly inefficient to type out and SELECT
199 columns.
So, thats a long winded way of asking: Is there a way to add a prefix or a suffix to the joined table automatically when joining it (eg. it would say table2_product_id
)? Or is there a faster way I am unaware of?
Edit: Theres actually 2 customer_id's
too which further supports my question.