clear markdown help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2591550 fiddles created (45729 in the last week).

CREATE TABLE categories ( category_id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL ); CREATE TABLE brands ( brand_id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL, created_at TIMESTAMP NOT NULL ); CREATE TABLE products ( product_id SERIAL PRIMARY KEY, brand_id INT NOT NULL, category_id INT NOT NULL, title VARCHAR(255) NOT NULL, created_at TIMESTAMP NOT NULL, CONSTRAINT fk_brand FOREIGN KEY(brand_id) REFERENCES brands(brand_id), CONSTRAINT fk_category FOREIGN KEY(category_id) REFERENCES categories(category_id) );
 hidden batch(es)


INSERT INTO brands(name, created_at) VALUES ('Apple', '2020-01-01'), ('Google', '2020-01-02'), ('Microsoft', '2020-01-03'); INSERT INTO categories(name) VALUES ('laptops'), ('phones'), ('tablets'); INSERT INTO products(brand_id, category_id, title, created_at) VALUES (1, 1, 'Macbook Pro', '2020-01-01'), (1, 2, 'iPhone SE', '2020-01-02'), (1, 3, 'iPad Air', '2020-01-03'), (2, 1, 'Pixelbook GO', '2020-01-04'), (2, 2, 'Pixel 5', '2020-01-05'), (3, 1, 'Surface 3', '2020-01-06');
3 rows affected
3 rows affected
6 rows affected
3 rows affected
3 rows affected
6 rows affected
 hidden batch(es)


SELECT * FROM brands;
brand_id name created_at
1 Apple 2020-01-01 00:00:00
2 Google 2020-01-02 00:00:00
3 Microsoft 2020-01-03 00:00:00
brand_id name created_at
1 Apple 2020-01-01 00:00:00
2 Google 2020-01-02 00:00:00
3 Microsoft 2020-01-03 00:00:00
 hidden batch(es)


SELECT * FROM categories;
category_id name
1 laptops
2 phones
3 tablets
category_id name
1 laptops
2 phones
3 tablets
 hidden batch(es)


SELECT * FROM products;
product_id brand_id category_id title created_at
1 1 1 Macbook Pro 2020-01-01 00:00:00
2 1 2 iPhone SE 2020-01-02 00:00:00
3 1 3 iPad Air 2020-01-03 00:00:00
4 2 1 Pixelbook GO 2020-01-04 00:00:00
5 2 2 Pixel 5 2020-01-05 00:00:00
6 3 1 Surface 3 2020-01-06 00:00:00
product_id brand_id category_id title created_at
1 1 1 Macbook Pro 2020-01-01 00:00:00
2 1 2 iPhone SE 2020-01-02 00:00:00
3 1 3 iPad Air 2020-01-03 00:00:00
4 2 1 Pixelbook GO 2020-01-04 00:00:00
5 2 2 Pixel 5 2020-01-05 00:00:00
6 3 1 Surface 3 2020-01-06 00:00:00
 hidden batch(es)


SELECT products.*, categories.* FROM products NATURAL JOIN categories;
product_id brand_id category_id title created_at category_id name
1 1 1 Macbook Pro 2020-01-01 00:00:00 1 laptops
2 1 2 iPhone SE 2020-01-02 00:00:00 2 phones
3 1 3 iPad Air 2020-01-03 00:00:00 3 tablets
4 2 1 Pixelbook GO 2020-01-04 00:00:00 1 laptops
5 2 2 Pixel 5 2020-01-05 00:00:00 2 phones
6 3 1 Surface 3 2020-01-06 00:00:00 1 laptops
product_id brand_id category_id title created_at category_id name
1 1 1 Macbook Pro 2020-01-01 00:00:00 1 laptops
2 1 2 iPhone SE 2020-01-02 00:00:00 2 phones
3 1 3 iPad Air 2020-01-03 00:00:00 3 tablets
4 2 1 Pixelbook GO 2020-01-04 00:00:00 1 laptops
5 2 2 Pixel 5 2020-01-05 00:00:00 2 phones
6 3 1 Surface 3 2020-01-06 00:00:00 1 laptops
 hidden batch(es)


SELECT products.*, brands.* FROM products NATURAL JOIN brands;
product_id brand_id category_id title created_at brand_id name created_at
1 1 1 Macbook Pro 2020-01-01 00:00:00 1 Apple 2020-01-01 00:00:00
product_id brand_id category_id title created_at brand_id name created_at
1 1 1 Macbook Pro 2020-01-01 00:00:00 1 Apple 2020-01-01 00:00:00
 hidden batch(es)


CREATE TABLE t1 ( a INT, b INT ); CREATE TABLE t2 ( a INT, b INT );
 hidden batch(es)


INSERT INTO t1 VALUES (1, 2), (3, 4), (5, 6); INSERT INTO t2 VALUES (3, 4), (5, 6), (7, 8);
3 rows affected
3 rows affected
3 rows affected
3 rows affected
 hidden batch(es)


SELECT * FROM ( SELECT 't1' AS t1, t1.* FROM t1 ) t1 NATURAL FULL JOIN ( SELECT 't2' AS t2, t2.* FROM t2 ) t2 WHERE t1 IS NULL OR t2 IS NULL;
a b t1 t2
1 2 t1
7 8 t2
a b t1 t2
1 2 t1
7 8 t2
 hidden batch(es)