SELECT TableA.*, TableB.*, TableC.*, TableD.*
FROM TableA
JOIN TableB
ON TableB.aID = TableA.aID
JOIN TableC
ON TableC.cID = TableB.cID
JOIN TableD
ON TableD.dID = TableA.dID
WHERE DATE(TableC.date)=date(now())
SELECT Books_Namn, Author_Namn, Author_Age, Store_Namn FROM books
JOIN Author ON Author_Id = Author_Author_Id
JOIN Books_has_Store ON Books_Books_Id = Books_Id
JOIN Store ON Store_Id = Store_Store_Id;
-- Using INNER JOING to join multiple tables
SELECT c.code, name, region, e.year, fertility_rate, unemployment_rate -- Select fields
FROM countries AS c -- From countries (alias as c)
INNER JOIN populations AS p -- Join to populations (as p)
ON c.code = p.country_code -- Match on country code
INNER JOIN economies AS e -- Join to economies (as e)
ON c.code = e.code AND p.year = e.year; -- Match on country code and year
SELECT t1.ks, t1.[# Tasks], COALESCE(t2.[# Late], 0) AS [# Late]
FROM
(SELECT ks, COUNT(*) AS '# Tasks' FROM Table GROUP BY ks) t1
LEFT JOIN
(SELECT ks, COUNT(*) AS '# Late' FROM Table WHERE Age > Palt GROUP BY ks) t2
ON (t1.ks = t2.ks);
SELECT
ticket.ticket_id,
a1.attr_val AS attr_val1,
a2.attr_val AS attr_val2,
a3.attr_val AS attr_val3
FROM ticket
LEFT JOIN attr a1 ON ticket.ticket_id=a1.ticket_id AND a1.attr_type=1
LEFT JOIN attr a2 ON ticket.ticket_id=a2.ticket_id AND a2.attr_type=2
LEFT JOIN attr a3 ON ticket.ticket_id=a3.ticket_id AND a3.attr_type=3
SELECT o.orderid, o.amount, i.description
2FROM orders o
3INNER JOIN items i
4ON o.itemid = i.itemid