php - Joined two tables & get results -
i'm having trouble joining 2 mysql tables & getting result want.
i have 2 tables , users table & times table. users table having id & name . time table having user_id & minutesspent. want times users name & times column result set. specific dates user ids not in times table. need null value such users.
i have tried several queries, every time i'm getting times user_ids available in times table. not getting other user_id's times null :(
select `users`.`name`,sum(`times`.`minutesspent`) `total` `users` left outer join `times` on `users`.`id` = `times`.`user_id` date(`date`) = '2015-06-03' group `users`.`name`
& have tried query
select `users`.`name`,sum(`times`.`minutesspent`) `total` ,case when times.user_id null 0 else 1 end `users` inner join `times` on `users`.`id` = `times`.`user_id` , `users`.`istimeenable` = 0 date(`date`) = '2015-06-03' group `users`.`name`
if 1 me this, great .
your clause turning left join inner join. try this:
select `users`.`name`,sum(`times`.`minutesspent`) `total` `users` left outer join `times` on `users`.`id` = `times`.`user_id` , date(`date`) = '2015-06-03' group `users`.`name`
Comments
Post a Comment