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 78367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:58:34+00:00 2026-05-10T20:58:34+00:00

Say I have 2 tables: Customers and Orders. A Customer can have many Orders.

  • 0

Say I have 2 tables: Customers and Orders. A Customer can have many Orders.

Now, I need to show any Customers with his latest Order. This means if a Customer has more than one Orders, show only the Order with the latest Entry Time.

This is how far I managed on my own:

SELECT a.*, b.Id FROM Customer a INNER JOIN Order b ON b.CustomerID = a.Id ORDER BY b.EntryTime DESC 

This of course returns all Customers with one or more Orders, showing the latest Order first for each Customer, which is not what I wanted. My mind was stuck in a rut at this point, so I hope someone can point me in the right direction.

For some reason, I think I need to use the MAX syntax somewhere, but it just escapes me right now.

UPDATE: After going through a few answers here (there’s a lot!), I realized I made a mistake: I meant any Customer with his latest record. That means if he does not have an Order, then I do not need to list him.

UPDATE2: Fixed my own SQL statement, which probably caused no end of confusion to others.

  • 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. 2026-05-10T20:58:35+00:00Added an answer on May 10, 2026 at 8:58 pm

    I don’t think you do want to use MAX() as you don’t want to group the OrderID. What you need is an ordered sub query with a SELECT TOP 1.

    select *  from Customers      inner join Orders          on Customers.CustomerID = Orders.CustomerID         and OrderID = (             SELECT TOP 1 subOrders.OrderID              FROM Orders subOrders              WHERE subOrders.CustomerID = Orders.CustomerID              ORDER BY subOrders.OrderDate DESC         ) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say that I have three tables, customers, orders and orderDetails. I'm doing this:
Lets say I have a Customers table and an Orders table with a one-to-many
Say I have a table which stores customers order IDs. Such as | Customer
I have a set of tables (say Account, Customer) in a schema (say dbo)
I have a table with two columns, customer id and order. Let's say I
Let's say I have two tables one called Customers and one called CustomerAddresses. Then
Lets say i have four tables i want to read from: customer customer_id, customer_name
I have this GUI that shows, let's say Customer Orders. When my client nailed
let's say I have two tables: USERS: User_Id Hansen Nilsen Jensen Bob and ORDERS:
Say I have an instance method that does many different things that I need

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.