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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:38:44+00:00 2026-06-17T07:38:44+00:00

I am kind of stuck.. I have two tables mysql > EXPLAIN event; +————-+————–+——+—–+———————+—————————–+

  • 0

I am kind of stuck..

I have two tables

mysql > EXPLAIN event;
+-------------+--------------+------+-----+---------------------+-----------------------------+
| Field       | Type         | Null | Key | Default             | Extra                       |
+-------------+--------------+------+-----+---------------------+-----------------------------+
| id          | int(11)      | NO   | PRI | NULL                | auto_increment              |
| name        | varchar(100) | NO   | MUL |                     |                             |
| extUrl      | varchar(192) | NO   |     |                     |                             |
+-------------+--------------+------+-----+---------------------+-----------------------------+

One event can have many

mysql> explain eventDate;
+----------------+--------------+------+-----+---------------------+-----------------------------+
| Field          | Type         | Null | Key | Default             | Extra                       |
+----------------+--------------+------+-----+---------------------+-----------------------------+
| id             | int(11)      | NO   | PRI | NULL                | auto_increment              |
| category_id    | int(11)      | NO   | MUL | 0                   |                             |
| event_id       | int(11)      | NO   | MUL | 0                   |                             |
| location_id    | int(11)      | NO   | MUL | 0                   |                             |
| name           | varchar(100) | NO   |     |                     |                             |
| eventDate      | timestamp    | NO   |     | 0000-00-00 00:00:00 |                             |
+----------------+--------------+------+-----+---------------------+-----------------------------+

I’d like to query the event by id, with the location_id of the next upcoming eventDate and I am stuck how to form that query

I currently have this

 SELECT
      e.id,
      d.location_id,
      d.eventDate
 FROM
      event e
          INNER JOIN eventDate d ON d.event_id = e.id AND d.eventDate >= CURRENT_TIMESTAMP
 WHERE
      e.id = 5107
 GROUP BY
      e.id
 ORDER BY
      d.eventDate ASC

Now this returns a result, but I GROUP BY event, so I am unsure how to ensure that really the next eventDate is selected. Also I didn’t use any aggregate function ( group by one, aggregate many ), which doesn’t seem to be a clean and clearly defined result requirement – MySQL is randomly selecting one of the eventDate rows now isn’t it?

  • 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-17T07:38:46+00:00Added an answer on June 17, 2026 at 7:38 am

    This should always give you the first upcoming event:

     SELECT
          e.id,
          d.location_id,
          d.eventDate
     FROM
          event e
              INNER JOIN eventDate d ON d.event_id = e.id
     WHERE
          e.id = 5107
          AND
          d.id = (SELECT d1.id FROM eventDate d1 WHERE d1.event_id = 5107 AND d1.eventDate >= CURRENT_TIMESTAMP ORDER BY d1.eventDate ASC LIMIT 1)
    

    But the better way is to add LIMIT 1 to your current query and removing the GROUP BY:

     SELECT
          e.id,
          d.location_id,
          d.eventDate
     FROM
          event e
              INNER JOIN eventDate d ON d.event_id = e.id AND d.eventDate >= CURRENT_TIMESTAMP
     WHERE
          e.id = 5107
     ORDER BY
          d.eventDate ASC
     LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have two tables: Table A has information about the stock holdings of
I have a following situation: So, receiver subscribes to two kind of events: eventA
I kind of stuck on how to implement this query - this is pretty
I am kind of stuck with an issue where I am unable to to
I'm kind of stuck with my heap sort here in php: <?php function heapSort($a,
http://removed.com/jquery/# First time playing with jQuery, and kind of stuck already. I'm expecting the
I am stuck in how to parse this kind of XML (with same element
Kind of a follow up to a question from yesterday. I have a hash
Kind of like this question I have many text snippets that I use many,
From a long time ago I have a memory which has stuck with me

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.