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

时间:2013-03-24 17:12:04

标签: sql database join

我对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'

1 个答案:

答案 0 :(得分:7)

您需要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'