Shmewnix
Shmewnix

Reputation: 1573

How to select a column that doesn't exist in a table and return a NULL result for all rows returned

I have a query, that I'm looking to select a column that doesn't exist and just fill it with "NULL" in the results. The data is being exported to a .CSV File for import to another database which has the column. For example:

My query is:

Select col1, col2, col3
from table1

Output is:

col1      col2     col3
 1          5        9
 2          6       10
 3          7       11
 4          8       12

I'd like the output to be:

col1      col2     col3    col4
 1          5        9     NULL
 2          6       10     NULL
 3          7       11     NULL
 4          8       12     NULL

Upvotes: 3

Views: 7481

Answers (2)

Mureinik
Mureinik

Reputation: 311063

You can select a null literal:

SELECT col1, col2, col3, NULL AS col4
FROM   mytable

Upvotes: 7

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49260

Select col1, col2, col3, null as col4 from table1

Upvotes: 4

Related Questions