Difference between revisions of "Join 3 Tables"

From rbachwiki
Jump to navigation Jump to search
 
Line 1: Line 1:
  === Join 3 Tables ===
  === Join 3 Tables ===
SELECT A.sales_date, A.order_id,  A.product_id, B.product_name, C.job_title
SELECT A.sales_date, A.order_id,  A.product_id, B.product_name, C.job_title
  FROM sales A INNER JOIN product B
  FROM sales A INNER JOIN product B
  ON A.product_id = B.product_id  
  ON A.product_id = B.product_id  

Latest revision as of 17:45, 2 November 2017

=== Join 3 Tables ===
SELECT A.sales_date, A.order_id,  A.product_id, B.product_name, C.job_title
FROM sales A INNER JOIN product B
ON A.product_id = B.product_id 
LEFT OUTER JOIN salesperson C
ON A.salesperson_id = C.salesperson_id;

Join 4 Tables

SELECT A.sales_date, A.order_id,  A.product_id, B.product_name, C.job_title, D.first_name, D.last_name
FROM sales A INNER JOIN product B
ON A.product_id = B.product_id 
LEFT OUTER JOIN salesperson C
ON A.salesperson_id = C.salesperson_id
INNER JOIN customer D
ON A.customer_id = D.customer_id;

Adding a Filter

SELECT A.sales_date, A.order_id,  A.product_id, B.product_name, C.job_title, D.first_name, D.last_name
FROM sales A INNER JOIN product B
ON A.product_id = B.product_id 
LEFT OUTER JOIN salesperson C
ON A.salesperson_id = C.salesperson_id
INNER JOIN customer D
ON A.customer_id = D.customer_id
WHERE C.JOB_TITLE = 'East Manager';


Back To Top- Home - Category