Nexus Archive

SQL JOINS

Joins are a just a way to connect 2 tables through Queries.

Now our database only has 1 table i.e. customers and to use joins we need 2 so lets just quickly create one...

CREATE TABLE orders(order_id VARCHAR(40) PRIMARY KEY, customer_id INTEGER NOT NULL, item VARCHAR(30) NOT NULL, price INTEGER NOT NULL, status TEXT);

We used a field customer_id to link the customers to their orders. Now lets add some data here.

INSERT INTO orders
VALUES
('OD1', 1, 'Mechanical Keyboard', 2000, 'PENDING'),
('OD2', 1, 'Noctua Fan', 1500, 'PENDING'),
('OD3', 7, 'Mechanical Keyboard', 2000, 'PENDING'),
('OD4', 5, 'Mechanical Keyboard', 2000, 'PENDING'),
('OD5', 5, 'Blades of Chaos', 9000, 'SHIPPED');

Now we can Join these 2 tables and see how Joins work !


Follow Inner Join to continue from here.

Browse Full SQL Page.

#SQL on the go