Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,536 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,252 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



help building sql query to get only the next immediate result

 
Reply to this topicStart new topic

help building sql query to get only the next immediate result

jeffmc21
post 31 Jul, 2008 - 08:43 AM
Post #1


New D.I.C Head

*
Joined: 27 Nov, 2007
Posts: 40


My Contributions


Have a table, similar to a sports schedule, called 'schedule'. I need to query the table to return on the next event based on the date.

The call I was trying to use is:

SELECT DATE_FORMAT(game_date,'%a, %b %d') as game_date FROM `schedule` WHERE `game_date` >= CURDATE() ORDER BY game_date LIMIT 1

The problem is that although today is July 31 and the events start on Aug 28 and run weekly, the call is returning results from the end of October, which are actually towards the end of the schedule.

Any ideas on how to refine the call to get the very next date after the Current Date?
User is offlineProfile CardPM

Go to the top of the page


Trogdor
post 31 Jul, 2008 - 09:44 AM
Post #2


D.I.C Regular

Group Icon
Joined: 6 Oct, 2006
Posts: 451



Thanked 2 times

Dream Kudos: 125
My Contributions


Are you sure there are entries in that table between now and October?
If so, you may have to start fiddling with date-math functions (dateadd etc)
As a side note, it is bad style to use any form of quotes in table or column names, and you have both `game_date` and game_date (without quotes) in your query.
User is offlineProfile CardPM

Go to the top of the page

jeffmc21
post 31 Jul, 2008 - 10:20 AM
Post #3


New D.I.C Head

*
Joined: 27 Nov, 2007
Posts: 40


My Contributions


QUOTE(Trogdor @ 31 Jul, 2008 - 09:44 AM) *

Are you sure there are entries in that table between now and October?
If so, you may have to start fiddling with date-math functions (dateadd etc)
As a side note, it is bad style to use any form of quotes in table or column names, and you have both `game_date` and game_date (without quotes) in your query.



I'm positive that there are dates in there. The October date is actually the final date. I was told by a friend to try order by Descending(?), and also to try naming the alias something other than the column name. Problem is, I'm not sure which one is the alias for the game_date column...is it the one in the dateformat parentheses or the one after the AS?

As far as the quotes, I copied and pasted that straight from the markup that PhPmyAdmin was providing. I'm new to this and don't know when to use quotes and when not to.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/7/08 09:46PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month