Srikanth Vaindam
Srikanth Vaindam

Reputation: 455

Get ALIAS as concatned column names

I am trying to concat multiple columns and get the output as single column.

example:

SELECT vendor_id || '|' || vendor_name FROM vendors;

output:

vendor_id || '|' || vendor_name
-------------------------------
100000001|abc_company
100000002|def_company

Here I am trying to get Column name as vendor_id|vendor_name instead of vendor_id || '|' || vendor_name

I tried using AS keyword in different ways but was unsuccessful.

when using below query, it was saying FROM keyword missing

SELECT vendor_id || '|' || vendor_name AS vid|vname FROM vendors;

Upvotes: 0

Views: 56

Answers (2)

If you really want the returned column name to be vid|vname you just need to quote it:

SELECT vendor_id || '|' || vendor_name AS "vid|vname"
  FROM vendors;

Note that vid|vidname will be case-sensitive so you'll need to specify it exactly as given if you use it elsewhere.

Best of luck.

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269773

You need to quote the output. Personally, I don't like to have quoted column names, so I would do:

SELECT vendor_id || '|' || vendor_name AS vid_vname
FROM vendors;

However, you would do it as:

SELECT vendor_id || '|' || vendor_name AS "vid|vname"
FROM vendors;

Upvotes: 0

Related Questions