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

  • Home
  • SEARCH
  • 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 9129665
In Process

The Archive Base Latest Questions

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

I am currently showing the last 5 events in my database where WHERE eventdate

  • 0

I am currently showing the last 5 events in my database where WHERE eventdate < CURDATE()
eg

    CREATE TABLE venues (
        id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        venue VARCHAR(255)
    ) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB;

    CREATE TABLE categories (
        id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        category VARCHAR(255)
    ) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB;

    CREATE TABLE events (
        id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        eventdate DATE NOT NULL,
        title VARCHAR(255),
        venueid INT,
        categoryid INT
    ) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB;

    INSERT INTO venues (id, venue) VALUES
    (1, 'USA'),
    (2, 'UK'),
    (3, 'Japan');

    INSERT INTO categories (id, category) VALUES
    (1, 'Jazz'),
    (2, 'Rock'),
    (3, 'Pop');

    INSERT INTO events (id, eventdate, title, venueid, categoryid) VALUES
    (1,20121003,'Title number 1',1,3),
    (2,20121010,'Title number 2',2,1),
    (3,20121015,'Title number 3',3,2),
    (4,20121020,'Title number 4',1,3),
    (5,20121022,'Title number 5',2,1),
    (6,20121025,'Title number 6',3,2),
    (7,20121030,'Title number 7',1,3),
    (8,20121130,'Title number 8',1,1),
    (9,20121230,'Title number 9',1,2),
    (10,20130130,'Title number 10',1,3);

    SELECT DATE_FORMAT(events.eventdate,'%M %d %Y') AS DATE, title,
    cats.category AS CATEGORY, loc.venue AS LOCATION
    FROM events
    INNER JOIN categories as cats ON events.categoryid=cats.id
    INNER JOIN venues as loc ON events.venueid=loc.id
    WHERE eventdate < CURDATE()
    ORDER BY eventdate DESC
    LIMIT 0 , 5

See fiddle below.

http://sqlfiddle.com/#!2/21ad85/14

I want to show the last 5 events in my database where the eventdate < (events.eventdate WHERE events.id =10)

so where it = 10 you should be able to see event id 9,8,7,6,5 where it = 9 you should be able to see 8,7,6,5,4 etc.

But I am not quite sure how to write it in sql. I think it should be along the lines of

WHERE eventdate < (events.eventdate WHERE events.id =10)

but this doesn’t work

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

    Maybe you need this?

    WHERE eventdate < (SELECT eventdate FROM events WHERE events.id =10)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a parameter to a URL but currently it isnt showing
I currently have the following code which delays showing a fixed bar after a
I am currently working on calendar showing starting date and ending date of various
Currently working with NSURLConnection. Found a great website showing important delegate methods coming with
I have a tableView showing an NSMutableArray of an object and I am currently
Sorry, newbie question I know, however I've currently got mySQL results only showing when
I am currently learning how to create classes and using indexers. I have created
I'm having an issue with the popup window showing the last element the user
I currently have my homepage showing the 6 oldest Stories posts from MongoDB I
For some reason, on a Droid, my <input type=text> field is not showing correctly.

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.