Jump to content

Querying Multiple tables - 3 or more in w3school sql


Deadgar

Recommended Posts

Hello Ladies and Gents,

 

I am new to sql and this forum so please forgive if I don't word my question very well. I'm having diffuculty retrieving data when trying to run more than 2 queries in w3schools course. I was trying to pull from customers, Orders, Products and OrderDetails as a training example to myself.

 

What i'm asking is, if someone is willing, can they please write out a granular query that I can follow. I get different errors when trying to tweek my query. I want to be able to pull 3 or more tables at a time but know I'm missing a fundimental step or steps during my process.

 

SELECT Orders.OrderID, Customers.CustomerName, Orders.EmployeeID, Products.ProductNameFROM OrdersINNER JOIN CustomersON Orders.CustomerID=Customers.CustomerID

AND Orders.EmployeeID;

 

I know I'm not doing my joins right for sure. I want to be able to pull a customers product, get the employee ID that took the order and the product that was associated with the order and go a bit further. Getting a few examples and explanations would really help me. I'm just not getting it and google isn't giving the answer I need as there are several sql applications that give different nuances of retrieving query information from tables.

 

Thank you community for taking the time to help me out. I just want to get to a point where I can answer a question instead of asking the question. Or maybe someone can point me to a great site that shows different and more detailed examples of running queries such as above.

 

Thank you,

 

-Edgar

 

Link to comment
Share on other sites

There should be plenty of explanations of joins both online and in books. Joins are used all the time in SQL. One problem with your join is that you do not join on the products table, but you are trying to select a column from it. The last line is also a problem, "AND Orders.EmployeeID" doesn't do anything. If the orders table has a column called productID that corresponds to the products table, then it would be like this:SELECT Orders.OrderID, Customers.CustomerName, Orders.EmployeeID, Products.ProductNameFROM OrdersINNER JOIN CustomersON Orders.CustomerID=Customers.CustomerIDINNER JOIN ProductsON Products.ProductID = Orders.ProductID

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...