一尘不染

如何在SQL中显示来自多个表的数据

sql

我对SQL比较陌生。我试图弄清楚如何满足此条件:customer_id, customer_last_name,order_id,order_item_id, product_name为居住在弗吉尼亚州的所有客户提供展示。

到目前为止,我已经知道了,但是我不确定如何一起显示这些值。任何帮助将不胜感激。

SELECT customer_id, cust_first_name
FROM demo_customers
WHERE cust_state= 'VA'

SELECT order_id
FROM demo_orders
WHERE customer_id= '1'

阅读 134

收藏
2021-05-23

共1个答案

一尘不染

你需要一个 JOIN

SELECT customer_id, cust_first_name, order_id, order_item_id, product_name
FROM demo_customers
INNER JOIN demo_orders on demo_orders.customer_id = demo_customers.customer_id
WHERE cust_state= 'VA'
2021-05-23