Danish Bin Sofwan
Danish Bin Sofwan

Reputation: 476

Add user defined value to a column in an sql query

I have an SQL query:

select DISTINCT shortname_chn from dim_channel; 

The query returns me data for example:

| shortname_chn (VARCHAR)  |
|__________________________|
|       MTV                |  
|       National Geographic|
|       Discovery          | 
|       ARY News           |

How can I manipulate the SQL query so that I can add an additional row to the returned rows.

Following is the result I wish to get after running some query:

| shortname_chn (VARCHAR)  |
|__________________________|
|       MTV                |  
|       National Geographic|
|       Discovery          | 
|       ARY News           |
|       ALL                |

Where the last row "ALL" is user defined, not present in the database.

In the above mentioned regard, I researched and came across this question : How to add a user defined column with a single value to a SQL query but it targets the problem of adding a whole new column.

Upvotes: 2

Views: 1481

Answers (2)

Rowland Shaw
Rowland Shaw

Reputation: 38130

You can simply do something like this by UNIONing with a query that returns your fake row, e.g.:

SELECT DISTINCT
            shortname_chn 

FROM        dim_channel

UNION ALL

SELECT      'ALL' AS shortname_chn 

Upvotes: 0

olegsv
olegsv

Reputation: 1462

select DISTINCT shortname_chn from dim_channel
UNION 
SELECT 'ALL'

Upvotes: 2

Related Questions