0

I have two tablee.

Table A
  ID
A001
A002
A003

Table B
 COUNTRY
      UK
     USA
 GERMANY
   CHINA

I'd like to list all posible combination from each ID and each CONTRY

My expected result should be:

A001        UK
A001       USA
A001   GERMANY
A001     CHINA
A002        UK
A002       USA
A002   GERMANY
A002     CHINA
A003        UK
A003       USA
A003   GERMANY
A003     CHINA
Shota
  • 515
  • 3
  • 18

3 Answers3

1

this is just cross join.

select * from tableA t1
cross join tableB
order by t1.ID 
Ed Bangga
  • 12,879
  • 4
  • 16
  • 30
1

You may use a CROSS JOIN here. Note for completeness that in MySQL, an inner join without any join criteria behaves like a cross join. So, we could actually try:

SELECT a.ID, b.COUNTRY
FROM TableA a
INNER JOIN TableB b
ORDER BY a.ID, b.COUNTRY;
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

You can use Cross Join to resolve it, Read @Sarath Avanavu's answer in this link to have a better understanding.

SELECT a.ID, b.COUNTRY
FROM TABLE a
Cross Join TABLE b
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56