TAGS :Viewed: 12 - Published at: a few seconds ago

[ Is it possible to select a column followed by a wildcard (to retrieve all columns) in SQL? ]

This might be a weird question, but I'll ask it anyway. When I'm working on queries, I'm usually interested in only a few particular columns at first and when I'm happy with the result, I'll add other columns to the query.

In other words: first I make it work, then I'll add the details. But I usually end up writing another query (that retrieves all table data) just above my "work-in-progress-query" in order to look at column names and inspect the data at a glance. It would be nice if that extra "retrieve all query" wasn't necessary and if I could just use a wildcard directly.

To state it simple: I'd like to do:

SELECT column, * from myTable;

So let's say I've got a table Person:

 id     name     description    number     categoryId    modified      created
---------------------------------------------------------------------------------
 1      Sven     Ugly man       42         67            2014-03-03    2014-03-03
 2      Anna     Pretty woman   25         33            2014-03-03    2014-03-03

Then I would like to do:

SELECT number, * from Person

Which should be leading to:

 number  id     name     description    number     categoryId    modified      created
--------------------------------------------------------------------------------------
 67     1      Sven     Ugly man       42         67            2014-03-03    2014-03-03
 33     2      Anna     Pretty woman   25         33            2014-03-03    2014-03-03

Is such a thing possible?

Answer 1


Yes it is possible, and used frequently when testing.

Its not encouraged, as the * results in messy returns with columns sharing names. (especially duplicated columns, refrences and keys etc)

Short answer Yes, but not sensible