php - Struggling to get month name by using mysql join query -
i want month name below query :
select a.`user_name`, month(b.`registered_month`) `users` a, `registered_details` b a.`user_id`=b.`user_id`
but returns null
value in month(b.registered_month)
field.
the month
function work on date fields. returns numeric month of given date (i.e. 1 2014-01-01). there function called monthname
gives name of month of given date.
one other note query. typically, join should use on
instead of join tables.
`users` join `registered_details` b on a.`user_id`=b.`user_id`
edit since registered_month numeric value (1,2,3 etc), you'll need use case statement
select case b.registered_month when 1 'january' when 2 'february' end case themonth
Comments
Post a Comment