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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:29:27+00:00 2026-06-16T18:29:27+00:00

I got two tables. A dealer table (id, name, etc.) and an event table

  • 0

I got two tables.
A dealer table (id, name, etc.) and an event table (id, did(dealerid), eid(fb eventid), venue, etc.) where I save the dealerid, eventid, eventurl and date from facebook.

I can get all data with this sql statement:

SELECT * FROM dealer as t_d INNER JOIN events AS t_e
ON t_d.id = t_e.did;  

This works fine.

1   Laden Dortmund  Stra    12  45525   Dortmund    DE  www.google.de   0201-123456 laden@dortmund.de   300 400 1   1   416364098428245 https://www.facebook.com/events/416364098428245/    2013-01-28
2   Laden Unna  Wurststr.   123 45130   Unna    DE  www.bing.de 0222-11223344   laden@unna.de   400 276 2   2   145457548940302 https://www.facebook.com/events/145457548940302/    2013-03-08
2   Laden Unna  Wurststr.   123 45130   Unna    DE  www.bing.de 0222-11223344   laden@unna.de   400 276 3   2   405092472902921 https://www.facebook.com/events/405092472902921/    2013-04-26 

As you can see, I get two rows for the dealer id 2, because there are two events listed.
How can I get the event, which is the closest to this date (today).

Later, there will be like 20 Dealer and for each one at least 3-4 events.

A hint would be nice, thank you!

UPDATE:
This is the solution!

SELECT  t_d.*, t_e.*, DATE_FORMAT(t_e.date,'%d.%m.%Y') as date
    FROM    dealer as t_d
    INNER JOIN events AS t_e
        ON t_d.id = t_e.did
    INNER JOIN
    (
        SELECT  did, MIN(date) minDate
        FROM    events
        GROUP BY did
    ) e ON  t_e.did = e.did AND
            t_e.date = e.minDate   

But is it somehow possible to display ALL dealers, even if no event exists for the dealer?

  • 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-16T18:29:28+00:00Added an answer on June 16, 2026 at 6:29 pm
    SELECT  t_d.*, t_e.*
    FROM    dealer as t_d 
            INNER JOIN events AS t_e
                ON t_d.id = t_e.did
            INNER JOIN
            (
                SELECT  did, MAX(date) maxDate
                FROM    events
                GROUP BY did
            ) e ON  t_e.did = e.did AND
                    t_e.date = e.maxDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got two tables: Event +----------+---------+--------------+ | event_id | name | date |
I've got two tables: TABLE A (columns: FirstValue, SecondValue, SeatNumber) currently empty TABLE B(1
I've got two tables with similar structure: - First table: id and col1,col2,col3 -
I have got two tables. One is a User table with a primary key
I have got two tables in SQL Server 2005: USER Table: information about user
I've essentially got two tables: Page(PK=url) and PageProperty(PK=url+name). Here is how I have my
I've got two tables: Topics -name and Queries -topic_id A query can have a
I got two tables: users and firms: class Firm extends AppModel { var $name
I've got two tables (let's say left and right tables). The right table's got
I've got two tables called hotels and hotel locations . In the hotels table

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.