Tech Junkie Blog - Real World Tutorials, Happy Coding!: SQL: RIGHT JOIN

Thursday, June 3, 2021

SQL: RIGHT JOIN

RIGHT JOIN works like the INNER JOIN, it just returns all the records that are on the right side of the = sign on the RIGHT JOIN clause. For example let's say you want to get a record of all customers who orders a certain product.



  RIGHT JOIN SQL Query
You will use the RIGHT JOIN by query all the orders in the Orders table then linking it to the OrderDetails table and then eventually linking it to the Products table.

SELECT c.CompanyName,c.ContactName,c.ContactTitle,od.OrderID,p.ProductID,p.ProductName
FROM Customers c
RIGHT JOIN Orders o ON o.CustomerID = c.CustomerID
RIGHT JOIN [Order Detailsod ON o.OrderID = od.OrderID
RIGHT JOIN Products p ON p.ProductID = od.ProductID

Here are the results:

RIGHT JOIN SQL Query Result
You can filter the results further by adding a WHERE clause for a specific product id.
SELECT c.CompanyName,c.ContactName,c.ContactTitle,od.OrderID,p.ProductID,p.ProductName
FROM Customers c
RIGHT JOIN Orders o ON o.CustomerID = c.CustomerID
RIGHT JOIN [Order Detailsod ON o.OrderID = od.OrderID
RIGHT JOIN Products p ON p.ProductID = od.ProductID 
WHERE p.ProductID = 33
Here are the results:
RIGHT JOIN SQL Query To Find Results With A Specific ID

9 comments:

  1. I want to show my thanks to the writer just for rescuing me from this matter. After exploring through the online world and meeting basics which were not powerful, I figured my entire life was done. Living without the approaches to the issues you have fixed all through your report is a critical case, and the ones that would have adversely affected my career if I had not discovered your website. Your good natural talent and kindness in playing with a lot of things was tremendous. I am not sure what I would've done if I hadn't encountered such a point like this. It’s possible to at this point look ahead to my future. Thanks so much for your reliable and amazing guide. I will not think twice to recommend the sites to anyone who would need support on this issue.Refer best essay writing service to get any help in writing.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I was more than happy to uncover this great site. I need to to thank you for your time due to this fantastic read!!
    I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.
    Classified Ads WordPress Theme

    ReplyDelete

  4. I was more than happy to uncover this great site. I need to to thank you for your time due to this fantastic read!!
    I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.
    Freelance Marketplace WordPress Theme

    ReplyDelete
  5. Thank you for sharing this information. Amazing Article!
    If you are looking for machine learning courses in Bangalore, visit Learnbay.co
    website to check details related to the data science online courses and online machine learning course.

    ReplyDelete

Search This Blog