如何在SQL中显示来自多个表的数据 [英] How to display data from multiple tables in SQL

查看:121
本文介绍了如何在SQL中显示来自多个表的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm relatively new to SQL. I'm trying to figure out how to satisfy this condition: Display customer_id, customer_last_name, order_id,order_item_id, product_name for any customer living in Virginia.

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

So far, I have this, but I'm not sure how to display the values together. Any help will be appreciated.

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

SELECT order_id
FROM demo_orders
WHERE customer_id= '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'

这篇关于如何在SQL中显示来自多个表的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆