In MySQL, I have a simple "SELECT * FROM foo"
query. I would like to JOIN
table 'bar', but:
- I only want one column from
bar
- I specifically DON'T want the
id
column frombar
, because it will conflict with theid
column fromfoo
I know that I could use as
statements to avoid name conflicts, but I don't want to complicate things. Is there a way to write this query without naming every column I want from foo
?
In other words, can I say 'give me all the columns from foo
and just this one column from bar
?
Update: Why this is bad practice
Folks have pointed out that "SELECT *"
is generally bad practice, because:
- It returns unnecessary data. That could, now or in the future, include something large, like a BLOB data column.
- If the database schema changes, the query may not return one of the expected columns. If the column is named explicitly in the query, there will be an error; if not, it may fail silently (insert a blank where a title should go, for example).