Craig van Tonder Craig van Tonder - 1 month ago 5
MySQL Question

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)

Answer

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`
)