【发布时间】:2013-07-01 09:49:26
【问题描述】:
我正在为我的项目使用 sql server 2008。我有两个表名为 1.Customer_Invoice 2.Orders.
并且两个表都有Customer_Invoice_ID 列。在Customer_Invoice 表中为PK,在Orders 表中为FK。
现在我的要求是获得top 100 records from Customer_Invoice 表和then for each Customer_Invoice_ID, i want all records from orders table。所以我想要 Customer_Invoice_ID 存在于 Customer_Invoice 表中的订单表中的所有记录。
首先,
Select top 100 * from Customer_Invoice
然后为每个Customer_Invoice_ID 获取来自Order table 的记录。
谁能指导我如何编写查询?
【问题讨论】:
标签: sql sql-server-2008 join