» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 07-12-2006, 03:03 PM
Garros Garros is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Garros is on a distinguished road
Default SQL question- help!!

hi all
I have a table for events with dates like this:
2006-01-01
2006-01-06
2006-01-15
2006-02-01
2006-02-15
2006-05-20
2006-07-15
2007-01-01
2007-01-12
How can I run a SELECT that will return results for all the events in certain months/years? So, the above data would return:
Jan 2006
Feb 2006
May 2006
July 2006
Jan 2007

many thanx for replies -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 07-12-2006, 03:11 PM
stumpted stumpted is offline
OSP Starters
 
Join Date: Jun 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
stumpted is on a distinguished road
Arrow

Hi, this should work for you

Code:
SELECT
column1
, column2
, DATE_FORMAT(date_column, '%b %Y') AS formatted_date
FROM some_table
ORDER BY YEAR(date_column) ASC, MONTH(date_column) ASC
;
hope it helps -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #3  
Old 07-12-2006, 03:13 PM
jesussaves jesussaves is offline
OSP Starters
 
Join Date: Jun 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
jesussaves is on a distinguished road
Default

This certainly worked for me,

SELECT DISTINCT date_format( calendar_date, '%b %Y' ) AS calendar_date_disp, calendar_date
FROM calendar
GROUP BY calendar_date_disp
ORDER BY calendar_date ASC

best of luck
thanks -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #4  
Old 07-12-2006, 03:16 PM
salisbury salisbury is offline
OSP Starters
 
Join Date: Jun 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
salisbury is on a distinguished road
Default

Your question is incorrect for two reasons.

1) the distinct works across the entire row and not just on a single column

2) the distinct is not necessary with the group by. However your group by clause must contain each column present in your select statement. Without that you may end up with incorrect values in your returned rows. See the manual for GROUP BY HIDDEN FIELDS. Note that all other databases would throw an error message for your code above for leaving the second column out of the group by clause.

I thought this way
have a good time -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about combining two DB records into one ASP Table richardson ASP forums and Tips 1 08-29-2006 02:35 PM
DiscountASP.NET Launches SQL Database Transfer Tool outsourcingplans Web Hosting News 0 08-09-2006 04:23 AM
DiscountASP.NET Introduces New Services outsourcingplans Web Hosting News 0 08-08-2006 07:42 AM
Re-invent Launches Free SQL 2005 Hosting outsourcingplans Web Hosting Industry 0 04-24-2006 08:41 PM
DiscountASP.NET Launches SQL 2005 & ASP.NET 2.0 Hosting outsourcingplans Web Hosting News 0 11-29-2005 02:50 PM


All times are GMT. The time now is 08:44 PM.