Craig van Tonder
Craig van Tonder

Reputation: 7687

Prepending a row in the result of a MySQL query?

Reading this answer to a SO question on how to append a row onto a MySQL result, we can do the following to append the value Jason to the names of Customers:

Select NAME
From Customers
UNION ALL
Select 'Jason'

So we end up with:

NAME
Actual Customer 1
Actual Customer 2
Jason

But how could we add Jason to the beginning of the results so what we have:

NAME
Jason
Actual Customer 1
Actual Customer 2

(Would like to do this without using Order By)

Upvotes: 0

Views: 103

Answers (1)

PaulF
PaulF

Reputation: 6773

Have you tried this

Select 'Jason' As `Name`
UNION ALL
Select Name
From Customers

If you want the second query ordered then use something like

Select 'Jason' As `Name`
UNION ALL
(Select `myDate`
From Customers
Order By `myDate`
)

Upvotes: 1

Related Questions