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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:49:05+00:00 2026-06-11T15:49:05+00:00

I Have a table which holds date but I need to know the latest

  • 0

I Have a table which holds date but I need to know the latest date where a condition is true per location, only issue is once I add a column called ‘notes’ it breaks the query and returns too many rows, current query is …

SELECT
        Location,
        MAX(date) AS date,
        type,
        notes
  FROM NotesTable a
 INNER JOIN Location b on a.LocationID = b.LocationID
 INNER JOIN Type c on a.typeid = c.typeid
 WHERE typeid <> 8
 GROUP BY Location, type, notes

If I comment out the notes column then it works fine but as soon as I add that to the grouping it then returns more rows than required.

Have tried using a subquery but still cant get it working, subquery below

SELECT
        r.location,
        r.date,
        r.type,
        t.notes
  FROM (SELECT Location, MAX(date), type
          FROM NotesTable a INNER JOIN Location b on a.LocationID = b.LocationID
         INNER JOIN Type c on a.typeid = c.typeid
         WHERE typeid <> 8
         GROUP BY location,type
        ) r
INNER JOIN NotesTable t ON t.date = r.date

Anyone got any other suggestions?

  • 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-11T15:49:06+00:00Added an answer on June 11, 2026 at 3:49 pm
    select * from
    (
         SELECT Location,Date, Type, Notes, Row_Number() Over (Partition By Location, Type order by date desc) RN 
         FROM
              NotesTable a
               INNER JOIN Location b on a.LocationID = b.LocationID
               INNER JOIN Type c on a.typeid = c.typeid
          WHERE typeid <> 8
    ) v
    WHERE rn = 1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which holds a list of criminal charges.These charges can be
I have a games table which holds the data about a game. Then another
I have a table called Town which holds a relation between player and a
I have a parent table called 'Website' which holds records about websites. I have
I currently have a table called paper , which holds all the information for
I have two tables with the following (simplified) structures: table "Factors" which holds data
I have a table in Postgres database logs which holds the error logs with
I have a table, which holds (besides all other data) information, when this data
I have a table which holds images of children. Now I want to read
I have a table which holds all views for the last 24 hours. I

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.