Skip to main content
Home
  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact
programsbuzz facebook programsbuzz twitter programsbuzz linkedin
  • Log in

Main navigation

  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact

MySQL: LEFT JOIN on Multiple Tables

Profile picture for user arilio666
Written by arilio666 on 11/29/2021 - 11:42

Now we all know that in MySQL, we have the concept of LEFT JOIN where the following query will join a table name from the left side with the table queried on the right side.

Here, the joining works in the way of all the left table content will be displayed and the right table content will be displayed with the respective matching pair of the left table content thus called the LEFT JOIN.

So enough said we will be doing a left join on multiple tables and see how that works out.

So today we will be using 3 tables orders, order_items, products for real-time examples to query out our needs out of these tables.

So here is what we are gonna do today:

  • We will be fetching products, their quantity, unit price, and shipped date out these 3 tables using the left join.

So let us dive straight into it then.

So let us perform the left join of these 3 tables in total and see how it comes out first.

select * from products p left join order_items oi ON oi.product_id = p.product_id left join orders o ON oi.order_id=o.order_id

  • So here we have left joined products table to order_items under the common column of product_id and left joined that order_items to orders table under the common column of order_id.
  • From the pic, we can conclude that all the records about the left side of the join are visible and the right side is displayed respectively to the matching columns.

Ok from this table let us filter out what we need which is the products and their quantity and their price and also their shipped date.

select p.name AS Product_name, p.quantity_in_stock AS Stock_Quantity, oi.quantity AS Order_Quantity, oi.unit_price AS Price,o.shipped_date from products p left join order_items oi ON oi.product_id = p.product_id left join orders o ON oi.order_id=o.order_id

  • So from here, we have taken out the Products along with their order quantity and price along with shipped date as we discussed using the LEFT join successfully.
Related Content
MySQL Tutorial
MySQL: Left Join
MySQL: Right Join
Tags
MySQL
  • Log in or register to post comments

Choose Your Technology

  1. Agile
  2. Apache Groovy
  3. Apache Hadoop
  4. Apache HBase
  5. Apache Spark
  6. Appium
  7. AutoIt
  8. AWS
  9. Behat
  10. Cucumber Java
  11. Cypress
  12. DBMS
  13. Drupal
  14. GitHub
  15. GitLab
  16. GoLang
  17. Gradle
  18. HTML
  19. ISTQB Foundation
  20. Java
  21. JavaScript
  22. JMeter
  23. JUnit
  24. Karate
  25. Kotlin
  26. LoadRunner
  27. matplotlib
  28. MongoDB
  29. MS SQL Server
  30. MySQL
  31. Nightwatch JS
  32. PactumJS
  33. PHP
  34. Playwright
  35. Playwright Java
  36. Playwright Python
  37. Postman
  38. Project Management
  39. Protractor
  40. PyDev
  41. Python
  42. Python NumPy
  43. Python Pandas
  44. Python Seaborn
  45. R Language
  46. REST Assured
  47. Ruby
  48. Selenide
© Copyright By iVagus Services Pvt. Ltd. 2023. All Rights Reserved.

Footer

  • Cookie Policy
  • Privacy Policy
  • Terms of Use