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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -