By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE table1 (
id int,
foo text
);
CREATE TABLE table2 (
id int,
bar text
);
INSERT INTO table1 VALUES
(1, 'abc'),
(2, 'bcd');
Records: 2 Duplicates: 0 Warnings: 0
INSERT INTO table2 VALUES
(1, 'abc'),
(2, 'BCDE'),
(3, 'bcd'),
(4, 'efg');
Records: 4 Duplicates: 0 Warnings: 0
SELECT * FROM table1, table2
id | foo | id | bar |
---|---|---|---|
2 | bcd | 1 | abc |
1 | abc | 1 | abc |
2 | bcd | 2 | BCDE |
1 | abc | 2 | BCDE |
2 | bcd | 3 | bcd |
1 | abc | 3 | bcd |
2 | bcd | 4 | efg |
1 | abc | 4 | efg |
SELECT * FROM table1 CROSS JOIN table2
id | foo | id | bar |
---|---|---|---|
2 | bcd | 1 | abc |
1 | abc | 1 | abc |
2 | bcd | 2 | BCDE |
1 | abc | 2 | BCDE |
2 | bcd | 3 | bcd |
1 | abc | 3 | bcd |
2 | bcd | 4 | efg |
1 | abc | 4 | efg |
SELECT * FROM table1, table2 WHERE table1.id = table2.id
id | foo | id | bar |
---|---|---|---|
1 | abc | 1 | abc |
2 | bcd | 2 | BCDE |
SELECT * FROM table1 CROSS JOIN table2 ON (table1.id = table2.id)
id | foo | id | bar |
---|---|---|---|
1 | abc | 1 | abc |
2 | bcd | 2 | BCDE |
SELECT * FROM table1 INNER JOIN table2 ON (table1.id = table2.id)
id | foo | id | bar |
---|---|---|---|
1 | abc | 1 | abc |
2 | bcd | 2 | BCDE |