Difference between revisions of "Join 3 Tables"

From rbachwiki
Jump to navigation Jump to search
Line 1: Line 1:
  SELECT A.sales_date, A.order_id,  A.product_id, B.product_name, C.job_title
  === 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
  FROM sales A INNER JOIN product B
  ON A.product_id = B.product_id  
  ON A.product_id = B.product_id  
  LEFT OUTER JOIN salesperson C
  LEFT OUTER JOIN salesperson C
  ON A.salesperson_id = C.salesperson_id;
  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;




[[#Select Command|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]]
[[#Select Command|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]]

Revision as of 19:58, 1 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;


Back To Top- Home - Category