简体   繁体   中英

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:

在此处输入图片说明

Customer table:

在此处输入图片说明

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

Thanks!

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM