If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Selecting "month/year" from table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-11-04, 14:36
wbrook wbrook is offline
Registered User
 
Join Date: Jan 2004
Posts: 8
Selecting "month/year" from table

Hi,

I have a table in a mysql db with a date column. I would like to retrieve a list of distinct month/year values from the table.

Any ideas how to formulate the sql query? For example, I know I could use:

select distinct month(date_field) from table_name

but this doesn't take into account the year.

Thanks!

(I tried asking this on another and got no answer - my apologies to anyone who reads this twice)
Reply With Quote
  #2 (permalink)  
Old 08-11-04, 15:33
lyndsey lyndsey is offline
Registered User
 
Join Date: Aug 2004
Posts: 4
try this TO_CHAR(Name_of_date_field, 'MM/YY') <--- this would take the 2 digits for month and year
Reply With Quote
  #3 (permalink)  
Old 08-11-04, 16:36
wbrook wbrook is offline
Registered User
 
Join Date: Jan 2004
Posts: 8
Thanks, Lindsey. That did the trick. (though since I am using mysql, I had to substitute to_char with date_format)

It was really simple, but I couldn't get it on my on. The other forum I had asked on berated me a bit and I was quite frustrated.

Thanks again for your help.
Reply With Quote
  #4 (permalink)  
Old 08-11-04, 22:05
lyndsey lyndsey is offline
Registered User
 
Join Date: Aug 2004
Posts: 4
you are welcome, and now i'm stuck with the tab-delimited hehe.. i'm supposed to write a query and the output should be tab-delimited format, but i don't know how to formulate the query
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On