Solved

TSQL - Find orders with more than one order line

Posted on 2009-07-10
3
177 Views
Last Modified: 2012-05-07
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
Comment
Question by:ComfortablyNumb
3 Comments
 

Expert Comment

by:cjonline
ID: 24821662
select * from orderstable inner join orderdetailtable on orderstable.orderid  = orderdetiltable.orderid where count(orderdetailstable.orderid) > 1
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 24821665
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
 

Author Closing Comment

by:ComfortablyNumb
ID: 31602000
Thank you very much. I've obviously got a lot to learn!!!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now