Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Easy SQL query?


  • Please log in to reply

#1
synapse5150

synapse5150

    New Member

  • Member
  • Pip
  • 2 posts
I thought this would be an easy SQL question, but I haven't found anyone who can help me.
I have a table with 3 fields: PERSONID, CONTACTID, and ORDERID. I need to pull the top 3 ORDERID's for each distinct PERSONID.
I would appreciate any help I can get with this, and I thank you all in advance!
  • 0

Advertisements


#2
synapse5150

synapse5150

    New Member

  • Topic Starter
  • Member
  • Pip
  • 2 posts
Here's the solution I came up with (Thanks Peso, Patron Saint of Lost Yaks):

SELECT MyTable.ContactID, MyTable.OrderID
FROM MyTable
WHERE MyTable.OrderID IN (SELECT TOP 3 x.OrderID FROM MyTable AS x WHERE x.ContactID = MyTable.ContactID)
ORDER BY MyTable.PersonID
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP