Add row to query result using select Add row to query result using select sql-server sql-server

Add row to query result using select


You use it like this:

SELECT  age, nameFROM    usersUNIONSELECT  25 AS age, 'Betty' AS name

Use UNION ALL to allow duplicates: if there is a 25-years old Betty among your users, the second query will not select her again with mere UNION.


In SQL Server, you would say:

Select name from usersUNION [ALL]SELECT 'JASON'

In Oracle, you would say

Select name from userUNION [ALL]Select 'JASON' from DUAL


is it possible to extend query results with literals like this?

Yes.

Select NameFrom CustomersUNION ALLSelect 'Jason'
  • Use UNION to add Jason if it isn't already in the result set.
  • Use UNION ALL to add Jason whether or not he's already in the result set.