join - Select MySQL Month() for null column -
got question ask. how list of left table display data when use left join when row got null value in it?
heres query:
select *, sum(transactions.debit_credit) current_spending (`budget`) left join `categories` on `budget`.`category`=`categories`.`idcategory` left join `user_category` on `budget`.`category`=`user_category`.`idcategory` left join `category_transaction` on `budget`.`category`=`category_transaction`.`idcategory` left join `transactions` on `category_transaction`.`idtransaction`=`transactions`.`idtransaction` `user_category`.`iduser` = '1' , month(transactions.transaction_date) = '11' group `budget`.`idbudget`; when remove and month(transactions.transaction_date) = '11' query works fine accept displays data instead of 1 month of transaction.
help?? please?? idea how??
your where clause turns left join inner join because filter data on condition of joined table.
instead put condition in on clause of join
select *, sum(transactions.debit_credit) current_spending (`budget`) left join `categories` on `budget`.`category`=`categories`.`idcategory` left join `user_category` on `budget`.`category`=`user_category`.`idcategory` , `user_category`.`iduser` = '1' left join `category_transaction` on `budget`.`category`=`category_transaction`.`idcategory` left join `transactions` on `category_transaction`.`idtransaction`=`transactions`.`idtransaction` , month(transactions.transaction_date) = '11' group `budget`.`idbudget`;
Comments
Post a Comment