How can I select from list of values in SQL Server

后端 未结 14 1863
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 18:08

I have very simple problem that I can\'t solve. I need to do something like this:

select distinct * from (1, 1, 1, 2, 5, 1, 6).

Anybody can

14条回答
  •  再見小時候
    2020-11-28 18:48

    PostgreSQL gives you 2 ways of doing this:

    SELECT DISTINCT * FROM (VALUES('a'),('b'),('a'),('v')) AS tbl(col1)
    

    or

    SELECT DISTINCT * FROM (select unnest(array['a','b', 'a','v'])) AS tbl(col1)
    

    using array approach you can also do something like this:

    SELECT DISTINCT * FROM (select unnest(string_to_array('a;b;c;d;e;f;a;b;d', ';'))) AS tbl(col1)
    

提交回复
热议问题