user12869508
user12869508

Reputation:

How Should I Combine These Two SQL queries into one?

I am trying to make an INNER JOIN statement that will join two tables, the Orders table and the Customer table, these both share the value/key of CustomerID. The Customer table has the information for which state a customer lives in. The Orders table has the information for which customer, according to their customer ID, bought which product. I need to find which products are the top 3 most popular in certain states. Please find the table descriptions images below, so you can understand what I mean.

Orders table:

enter image description here

Customer table:

enter image description here

How can I make this INNER JOIN statement and include the logical operators (and/or) to make this happen?

Thanks!

Upvotes: 0

Views: 56

Answers (1)

Chameera Dulanga
Chameera Dulanga

Reputation: 228

Try this,

SELECT column_name(s)
FROM Customer
INNER JOIN Order
ON Customer.CustomerID= Order.Customer_ID AND <conditions>;

Inner Join is just only 1 way of joining 2 tables. You can also join these two tables using WHERE closure as follows,

SELECT column_name(s)
FROM Customer c, Order o
WHERE c.CustomerID = o.Customer_ID AND <condition>

Upvotes: 1

Related Questions