Solved

Query details from query results?

Posted on 2011-02-10
4
277 Views
Last Modified: 2012-05-11
I need to get some result details based on a seperate query result.

I have two tables, Order and OrderDetails.

I need to pick out all the orders in Orders that were ordered by the same Cust# on the same OrderDate. Sum  (Orders > 1) .

Using those specific order numbers I need to pull out the orderdetails description.

I know this is a little vague but I think it describes the basic need. The results of one query will determine what is pulled by the second query.

Thanks
0
Comment
Question by:LanBuddha
  • 2
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34866974
post sample data or better upload a copy of the db..
0
 
LVL 2

Author Comment

by:LanBuddha
ID: 34867064

Order#     OrderDate#      Cust#
123           1/1/2011          1
124           1/1/2011          1
125           1/2/2011          3
126           1/3/2011          4

I should pull back order 123 and 124 because they were placed on same day by same customer.

OrderDetails
Order#      Desc
123          Product1
123          Product2
124          Product3
125          Product1

I need the details of order# 123 and 124 based on previous table.

Thanks
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 34867149
test this query


SELECT Order.OrderDate, Order.CustNo, Order.OrderNo,OrderDetails.Desc
FROM [Order] Inner Join [OrderDetails]
ON [Order].OrderNo=[OrderDetails].OrderNo
WHERE (((Order.OrderDate) In (SELECT [OrderDate] FROM [Order] As Tmp GROUP BY [OrderDate],[CustNo] HAVING Count(*)>1  And [CustNo] = [Order].[CustNo])))
ORDER BY Order.OrderDate, Order.CustNo;
0
 
LVL 2

Author Closing Comment

by:LanBuddha
ID: 34867701
Great. Got me where I need to be. Nice, quick response.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 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