Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TSQL - Find orders with more than one order line

Posted on 2009-07-10
3
Medium Priority
?
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 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