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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:04:15+00:00 2026-05-18T03:04:15+00:00

So, the query I’m trying to make looks like this right now: SELECT `jid`,

  • 0

So, the query I’m trying to make looks like this right now:

SELECT `jid`, MAX(`start`) as `start` FROM `dates` WHERE `start` < NOW() GROUP BY `jid`

The table dates basically holds a DATETIME value start associated with a job.
As you probably guessed, jid is the id of a job, stored in another table.
A job can have many dates

What I’m trying to accomplish is to find out what jobs have all their start dates in the past.

My thought was to select the highest values of the start dates, grouped by jid and if they were in the past, it would imply that all other dates associated with the same job are also in the past.

This query isn’t working because it’s checking for start dates in the past and then selecting the highest of those. This doesn’t exclude the possibility of another date for the same job, lying in the future.

I have no idea how I could proceed now. Any help or clue is appreciated.

Cheers – Tom

  • 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-18T03:04:19+00:00Added an answer on May 18, 2026 at 3:04 am

    You have to use HAVING :

    SELECT jid, MAX(start) as start
    FROM dates
    GROUP BY jid
    HAVING MAX(start) < NOW();
    

    HAVING acts a bit like WHERE. It filters out the rows after they were selected. Usually (and actually, I can’t think of any other case), you only use HAVING with aggregate functions.

    (I hope you really inserted dates in the future in your table, though!)

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

Sidebar

Related Questions

Query: SELECT * FROM table WHERE fieldA LIKE '%%' AND fieldB LIKE '%%' AND
Query: SELECT TOP 1 ReportInvoked , EmailSent FROM tblReportInvoker WHERE WebUserId = 12345 This
Query: SELECT StartDate, EndDate, RIGHT(Sector, 1 ) FROM Table1 ORDER BY Right(Sector, 1), StartDate
This query works great: var pageObject = (from op in db.ObjectPermissions join pg in
A query runs fast: DECLARE @SessionGUID uniqueidentifier SET @SessionGUID = 'BCBA333C-B6A1-4155-9833-C495F22EA908' SELECT * FROM
Which query would run faster? SELECT * FROM topic_info LEFT JOIN topic_data ON topic_info.id
Query: SELECT DISTINCT ([Equipment List].ID) AS Expr1, [Job Assignments].Job FROM [Equipment List] LEFT JOIN
query 1 : this will count all the record with email 'emali@test.com' select count(*)
Query - Select * FROM tbl1 LEFT OUTER JOIN tbl2 ON tbl1.id = tbl2.id
Query SELECT ppc.personid, ppc.category, ppc.phonenumber, ppc.createts FROM person_phone_contacts ppc WHERE CURRENT_TIMESTAMP BETWEEN ppc.createts AND

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.