Welcome to Dream.In.Code
Become an Expert!

Join 150,137 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,255 people online right now. 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
31 Jul, 2008 - 07:43 AM
Post #1

New D.I.C Head
*

Joined: 27 Nov, 2007
Posts: 48


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
+Quote Post

Trogdor
RE: Help Building Sql Query To Get Only The Next Immediate Result
31 Jul, 2008 - 08:44 AM
Post #2

D.I.C Addict
Group Icon

Joined: 6 Oct, 2006
Posts: 549



Thanked: 4 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
+Quote Post

jeffmc21
RE: Help Building Sql Query To Get Only The Next Immediate Result
31 Jul, 2008 - 09:20 AM
Post #3

New D.I.C Head
*

Joined: 27 Nov, 2007
Posts: 48


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
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:01AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month