select *,colname | select colname,* that is the question

Posted: 28th October 2010 by Darren Cassar in Beginner, MySQL

Strangely enough, select *,colname from tbname; works just fine, whereas select colname,* from tbname; fails! So if you would like to see all columns, but have one or more of them displayed to the left of the set, you have only one way left to do it ‘comfortably’:

select colname,tbname.* from tbname; well two really but this is really the same
select colname,tb.* from tbname tb;

Because Sharing is Caring

VN:F [1.9.22_1171]
Rating: 2.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

select *,colname | select colname,* that is the question, 2.0 out of 10 based on 1 rating

  1. raj says:

    as a DBA, I have to say, any select that has a ‘*’ in it is bad. I might use select * when I am running ad-hoc queries, but would never recommend it in production in any fashion. Name the columns.

  2. Agreed Raj, select * from table is NOT good (bad performance, memory issues, caching issues etc), one should know what they need and select specific columns. This case was simply a developer debugging some sql on qadev and wanted to see the bigger picture, yet starting the result set with a particular column.