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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:03:23+00:00 2026-06-19T04:03:23+00:00

I am working on a SQL Server 2008 database. I need to get a

  • 0

I am working on a SQL Server 2008 database. I need to get a specific order for a customer and their latest order ID and latest order data. My challenge here is, I need the data in a single row. Currently, I’m trying the following query:

 SELECT
  o.*,
  c.[FirstName],
  c.[LastName],
  c.[PlayerName],
  (SELECT TOP 1 o2.CreatedDate, o2.ID  FROM [Order] o2 ORDER BY [CreatedOn] DESC)
 FROM
  [Order] o,
  [Customer] c
 WHERE  
  o.[ID]=c.[CustomerID]

When I execute this query, I get the following error:

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

As you can imagine, there are scenarios where a customer will NOT have a previous order. How do I do this and get the result into a single row?

Thank you!

  • 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-19T04:03:24+00:00Added an answer on June 19, 2026 at 4:03 am

    Slightly different way to do it using a CTE.

    WITH LatestOrder AS (SELECT TOP 1 * FROM [Order] ORDER BY [CreatedOn] DESC) 
     SELECT
      o.*,
      c.[FirstName],
      c.[LastName],
      c.[PlayerName],
      lo.CreatedDate,
      lo.ID
     FROM [Order] o
     JOIN [Customer] c
        ON o.[ID]=c.[CustomerID]
     CROSS JOIN LatestOrder lo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a live SQL Server 2008 database and I need to start working
I'm working on a SQL Server 2008 database. This database has two tables. Book
I'm working on a database(school project). I need some testing for that database(SQL Server
i am working on visual stdio 2008 and my database is in sql server
I'm currently working my way through the Microsoft SQL Server 2008 - Database Development
I have a SQL Server 2008 database, and I need a mergereplication because i
I am working with a SQL Server 2008 R2 BIDS 2008 solution. I need
Hello I am working on a SQL database Using Microsoft SQL server 2008 R2
I'm working on a multi-user internet database-driven website with SQL Server 2008 / LinqToSQL
I'm working on performance tuning my SQL Server 2008 database and am using the

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.