SELECT customerId, customerName, city FROM customers
SELECT * FROM products
: you can select all columns with *
SELECT customerId, productId FROM customers, products
SELECT customerName, orderId FROM customers JOIN orders ON customers.customerId = orders.customerId
SELECT customerName, orderId FROM customers LEFT JOIN orders ON customers.customerId = orders.customerId
Not implemented.
Not implemented.
SELECT * FROM customers JOIN orders ON customers.customerId = orders.customerId JOIN orderDetails ON orders.orderId = orderDetails.orderId JOIN products ON orderDetails.productId = products.productId
Without (we will get multiple lines for each customer if there is multiple time this city in the world):
SELECT * FROM customers JOIN cities ON customers.city = cities.cityName
To avoid that we could do this (not working) :
SELECT * FROM customers JOIN cities ON customers.city = cities.cityName AND customers.country = cities.cityCountry
We handle those operators :
- AND
- OR
- NOT
TODO :
- ANY
- BETWEEN
- EXISTS
- IN
- LIKE
- SOME
We can handle those comparators :
- = : equal
- <> : not equal
-
: greater
-
= : greater or equal
- < : lesser
- <= : lesser or equal
We handle multi columns ordering, ASC and DESC support. Syntax : ORDER BY col1 ASC/DESC, col2 ASC/DESC ...
SELECT * FROM customers JOIN orders ON customers.customerId = orders.customerId JOIN orderDetails ON orders.orderId = orderDetails.orderId JOIN products ON orderDetails.productId = products.productId ORDER BY productId DESC, quantity ASC
We handle multiple conditions. We can compare strings, char, integer and double values.
SELECT * FROM customers WHERE city = Memphis
SELECT * FROM customers WHERE city = Memphis AND country = USA
SELECT * FROM customers WHERE city = Memphis OR country = USA
SELECT * FROM customers WHERE city = Memphis NOT country = USA
SELECT * FROM customers JOIN orders ON customers.customerId = orders.customerId JOIN orderDetails ON orders.orderId = orderDetails.orderId JOIN products ON orderDetails.productId = products.productId WHERE productId = 1
TODO : Other operators (LIKE, ...)
We can use joins, * selector, where, and order by at the same time.
SELECT * FROM customers JOIN orders ON customers.customerId = orders.customerId JOIN orderDetails ON orders.orderId = orderDetails.orderId JOIN products ON orderDetails.productId = products.productId WHERE productId = 1 ORDER BY customerId DESC
We can also chains conditions here. If no conditions are provided all lines from the table are removed.
DELETE FROM cities WHERE cityName = Mexico
We can also chains conditions here. If no conditions are provided all lines from the table are updated.
UPDATE cities SET cityName = Mexico2, cityPopulation = 555 WHERE cityId = 3
INSERT INTO cities ( cityId, cityName, cityCountry ) VALUES ('val_1', 'val_2', 'val_3')
We can't use different join type in a query. It won't crash but the result will be incorrect.