Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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