Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

join of value lists in postgres

I need to join two value lists in postgres.
I tried the following but it does not work;

select a.*,b.* from (values('a'),('b')) as a join (values('1'),('2'),('3')) as b ;

What should I write instead ;
The result should be a table of 6 values.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I assume you want to cross join values so that you will get 6 values.

select
    a.*,
    b.* 
  from (values('a'),('b')) as a (a),  
  (values('1'),('2'),('3')) as b (b);
a | b
--|--
a | 1
b | 1
a | 2
b | 2
a | 3
b | 3

Here is another statement with same result (with join clause)

select
    a.*,
    b.* 
  from (values('a'),('b')) as a (a)
  cross join (values('1'),('2'),('3')) as b (b);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading