Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8300369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:32:31+00:00 2026-06-08T16:32:31+00:00

i need a list from all products that contains 2 columns with the date

  • 0

i need a list from all products that contains 2 columns with the date the product was first ordered and the ordered quantity of this product.

Structure:
tbl_product
– productID
– productName

tbl_orderProduct
– orderProductID
– orderID
– productID
– quantity

tbl_order
– orderID
– orderedDate

SELECT p.productName, firstOrder.orderedDate FROM tbl_product p
LEFT JOIN(
    SELECT op.productID, MIN(o.orderedDate) AS orderedDate FROM tbl_orderProduct op
    JOIN tbl_order o ON op.orderID = o.orderID
    GROUP BY op.productID
)
firstOrder ON firstOrder.productID = p.productID

My first attempt to retrieve the date works so far but i can’t figure out how to get the quantity because i have to get the Order and then go back to tbl_orderProduct for the quantity.
I don’t want to get the order by select via the firstOrder.ordererdDate because there’s a chance that it’s not unique.

Also i can’t pass the orderID it with the select in my ‘Left Join’ because i also have to add it in the ‘Group By’ then and it would return a row for every order that contains the product.
So somehow i have to retrieve the orderID or the orderProductID from the First Order.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:32:33+00:00Added an answer on June 8, 2026 at 4:32 pm

    Assuming you’re using at least SQL-Server2005, you can use a common-table-expression with ROW_NUMBER function:

    WITH CTE AS
    (
       SELECT p.productName, o.orderedDate, quantity
       , RN = ROW_NUMBER() OVER ( PARTITION BY p.productID ORDER BY o.orderedDate )
       FROM tbl_product p 
       INNER JOIN tbl_orderProduct op ON p.productID=op.productID
       INNER JOIN tbl_order o ON op.orderID=o.orderID
    )
    SELECT * FROM CTE WHERE RN = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, _collection is a List from which I need to remove all
I need to extract all MP3 titles from a fuzzy list in a list.
I need a list from OldGuids that are not in the NewGuids, so I
Below are my classes. I have a product that contains list of days. Each
I need to get items from a html list from the vb.net code behind
I am loading a radiobutton list from an enumeration (vertically displayed). I need to
I`v come across a need where I want to create multiple list items from
I have three lists, I need to move Animal object from list animalSource to
I need to pull a list of items from a MySQL database and then
i need to get items from a List with no leading or trailing white

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.