query multiple tables sql code example
Example 1: join multiple tables sql
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())
Example 2: sql query multiple tables
SELECT t1.name, t2.salary FROM t1 JOIN t2 on t1.id = t2.id;
SELECT t1.name, t2.salary FROM t1 LEFT OUTER JOIN t2 on t1.id = t2.id;
SELECT emp_name AS name from employees
UNION
SELECT cust_name AS name from customers;
SELECT emp_name AS name from employees
UNION ALL
SELECT cust_name AS name from customers;