Solved

TSQL - Find orders with more than one order line

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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