How to use concatenation '||' with a separate clause of a SELECT query?

I get the missing expression error when I try,

SELECT 'label1:'||distinct col1 from tab1;

Is there any way around this error? Thanks in advance.

Edit: All request:

SELECT 'label1:'||distinct col1 from tab1 order by col1;
+3
source share
3 answers

try this one

SELECT  DISTINCT 'label1:' || col1
FROM tab1 order by 1;
+3
source

The first mistake is what distinctis in the wrong place.

SELECT distinct 'label1:'|| col1 as c 
from tab1
ORDER BY c;

The second one mentioned in the comments is that you ordered col1. You need to add the alias of the new column and order the alias as described above. (Note that you can use col1as an alias if you want)

+2
source

DISTINCT SELECT, :

SELECT  DISTINCT 'label1:' || col1
FROM    tab1

Update:

ORDER BY,

SELECT  'label1:' || col1
FROM    (
        SELECT  DISTINCT col1
        FROM    tab1
        )
ORDER BY
        col1
+2

Source: https://habr.com/ru/post/1752431/


All Articles