Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

TSQL - Find orders with more than one order line

This problem has screwed with my heads for long enough!

I have an Order table and and Order Lines table. I need to identify the orders that have more than one order line. Each order line has the Order ID referenced to it. All I really need is the Order Numbers identifed.

Any help would be greatly appreciated!
0
ComfortablyNumb
Asked:
ComfortablyNumb
1 Solution
 
cjonlineCommented:
select * from orderstable inner join orderdetailtable on orderstable.orderid  = orderdetiltable.orderid where count(orderdetailstable.orderid) > 1
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
Hope this helps
SELECT ot.order_id, count(order_line_id) cnt
FROM [ORDER] ot, order_lines ol
WHERE ot.orderid = ol.order_id
GROUP BY ot.order_id
HAVING count(order_line_id) > 1

Open in new window

0
 
ComfortablyNumbAuthor Commented:
Thank you very much. I've obviously got a lot to learn!!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now