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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:07:34+00:00 2026-05-23T02:07:34+00:00

I need to do a left outer join like this: SELECT tblProjects.*, tblNotes.NoteID, tblNotes.regDate

  • 0

I need to do a left outer join like this:

SELECT 
    tblProjects.*, 
    tblNotes.NoteID,
    tblNotes.regDate AS lastUpdatedNote
FROM 
    tblProjects 
    LEFT OUTER JOIN tblNotes ON tblProjects.ProjectID = tblNotes.ProjectID

But a project can have several notes and in this case im only interested in the one with MAX(regDate) how can i add this condition to the sql above? Or do i have to grab all the notes for each project and filter out the latest in code?

So i only want one row per project and in that row i want the lastUpdatedNote info.

Thx 🙂

  • 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-05-23T02:07:35+00:00Added an answer on May 23, 2026 at 2:07 am

    In MS SQL you can do something like this:

    SELECT 
        tblProjects.*, 
        tblNotes.NoteID,
        tblNotes.regDate AS lastUpdatedNote
    FROM tblProjects 
    OUTER APPLY
    (
        SELECT TOP 1 NoteId, regDate
        FROM tblNotes
        WHERE tblProjects.ProjectID = tblNotes.ProjectID
        ORDER BY tblNotes.regDate DESC
    ) tblNotes
    

    Replace with CROSS APPLY if you need only those projects that have notes.

    or with CTE:

    WITH cte
    AS
    (
        SELECT *, ROW_NUMBER() OVER(PARTITION BY NoteId ORDER BY RegDate DESC) RowNumber
        FROM tblNotes
    )
    SELECT tblProjects.*, cte.NoteID, cte.RegDate
    FROM tblProjects 
        LEFT JOIN cte on
            tblProjects .ProjectId = cte.ProjectId AND RowNumber = 1
    

    Replace with INNER JOIN if you need only those projects that have notes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a sub-select in a query that looks something like this: left outer
hi i tried a select query that contains an left outer join on SQL
I have a query of the form: select m.id from mytable m left outer
I have an MySQL query like this: SELECT MAX(messages.ID) as maxID, messages.from, messages.read, users.userName
I need to do this in nhibernate QueryOver: select distinct sc.* from [Security].[Commands] sc
I need to get the left hand side integer value from a decimal or
I need to make multiple divs move from right to left across the screen
Is it possible to join the results of a SELECT with another table. Like
So I have an SQL statement looks like this SELECT T1.NAME, COUNT(T2.VALUE) AS numInstances
I've got a collection (List<Rectangle>) which I need to sort left-right. That part's easy.

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.