MYSQL Query don't return which have no relation on Join Query -


i wrote query data table "user" , corresponding "transaction" count table "service" . i've 100 user on table 1 . 2 user have relation service table. query return 2 results. used left outer query getting users have not relation service table.

here query:

select users.*,  count(service.recipient_number) total_transaction `users` left outer join service on users.id = service.office_id (users.del_status = 0 , service.del_status = 0 ,  users.type="agency")  group users.office_name  

present output:

 username  total_transaction +++++++++++++++++++++++++++++++++++++    dhaka         2    ctg           1 

desire output:

  username  total_transaction   +++++++++++++++++++++++++++++++++++++    dhaka         2    ctg           1    sylhet        0    comilla       0    mym           0 

select users.office_name,        count(service.recipient_number) total_transaction  `users` left outer join service on users.id = service.office_id                         , service.del_status = 0                         , year(curdate()) = year(service.creation_time)                          , month(curdate()) = month(service.creation_time) users.del_status = 0   , users.type = 'agency' group users.office_name  

you need put where conditions regarding joined table, directly join.

why? because where clause filters complete result set. join conditions filter joined table result.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -