I use beeline, which is a JDBC client based on SQLLine, to run Hive queries. I would like to select from a liste of values like:
SELECT DISTINCT * FROM (a,b,b,c,d,..z)
is that posssible?
I use beeline, which is a JDBC client based on SQLLine, to run Hive queries. I would like to select from a liste of values like:
SELECT DISTINCT * FROM (a,b,b,c,d,..z)
is that posssible?
SELECT DISTINCT *
FROM (
SELECT 12
UNION SELECT 23
UNION SELECT 34
UNION SELECT 12
UNION SELECT 23
) AS t1;
PS: also refer to very closely related question How can I select from list of values in SQL Server
Also you can use stack
, it works much faster than UNION:
hive> select id from
> (
> select stack(5, --the number of elements
> 10 ,
> 20 ,
> 30 ,
> 40 ,
> 50
> ) as (id)
> )s;
OK
10
20
30
40
50
Time taken: 4.88 seconds, Fetched: 5 row(s)
You may try split
and explode
SELECT DISTINCT * FROM
(
select explode( split('a,b,b,c,d,e,f' ,',')) c
) as t
ORDER BY c