Solved

TSQL - Find orders with more than one order line

Posted on 2009-07-10
3
178 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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