Solved

TSQL - Find orders with more than one order line

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use TOP 1 in a T-SQL sub-query? 14 48
How can I get this column in my query? 2 56
CREATE DATABASE ENCRYPTION KEY 1 80
Need to find substring in SQL 5 41
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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