SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist cronsrcs's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting the next upcoming events

    I have a db table that stores "events". What i want to do is display the next 3 upcoming events, with the event which is next to occur to be the first in the list.

    Here is the sql I have at present:

    SELECT art_id, art_title, art_date
    FROM Article
    WHERE art_type =1 AND archived = 0 AND art_date >= "the current date"
    ORDER BY art_date DESC limit 3

    I am not sure that this is going to give me exactly what I want.

    Any ideas?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select *
      from (
           select art_id, art_title, art_date
             from Article
            where art_type = 1 
              and archived = 0 
              and art_date >= current_date
           order 
               by art_date desc limit 3
           ) as dt
    order
        by art_date asc
    use the current_date keyword, luke

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •