By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,740 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,740 IT Pros & Developers. It's quick & easy.

Help with select query

P: n/a
Suppose I have a table Orders with the following fields:

OrderID ProductID OrderDate

I would like a SELECT query to return those rows with multiple values
for both ProductID and OrderDate. For example suppose Orders contains
the following data

OrderID ProductID OrderDate
1 11 12-mar-2005
2 13 13-mar-2005
3 13 13-mar-2005
4 13 13-mar-2005
5 13 14-mar-2005
5 14 14-mar-2005
6 15 15-mar-2005
7 15 15-mar-2005

then the query would return the rows corresponding to OrderID's 2, 3,
4, 6, 7.
How can this be done?
Thanks.

Dec 6 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
SELECT OrderID,ProductID,OrderDate
From YourTable

Where OrderID in (2, 3,4, 6, 7)

HTH, Jens Suessmeyer.

Dec 6 '05 #2

P: n/a
Try:

select
o.*
from
Orders
join
(
select
ProductID
, OrderDate
from
Orders
group by
ProductID
, OrderDate
having
count (*) > 1
) x on x.ProductID = o.ProductID
and x.OrderID = o.OrderID

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada to*@cips.ca
www.pinpub.com

"Bruno Panetta" <bp******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Suppose I have a table Orders with the following fields:

OrderID ProductID OrderDate

I would like a SELECT query to return those rows with multiple values
for both ProductID and OrderDate. For example suppose Orders contains
the following data

OrderID ProductID OrderDate
1 11 12-mar-2005
2 13 13-mar-2005
3 13 13-mar-2005
4 13 13-mar-2005
5 13 14-mar-2005
5 14 14-mar-2005
6 15 15-mar-2005
7 15 15-mar-2005

then the query would return the rows corresponding to OrderID's 2, 3,
4, 6, 7.
How can this be done?
Thanks.

Dec 6 '05 #3

P: n/a
Thanks a lot! That was very helpful.

Dec 8 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.