COALESCE(SUM(), 0) JOINED table column with GROUP BY not showing all results
I am trying to build a query that retrieves all reservations within a date timeframe and joins a payment table to calculate total payments, and few other things. The query seems to work just fine except it is leaving out reservations that have no payments. Any help would be greatly appreciated. SELECT reservations.reservation_id , properties. NAME , properties.address1 AS prop_address , reservations.last_name , reservations.arrival_date , reservations.departure_date , reservations.date_created , reservations.contract_filename , reservations.contract_signed , reservation_payments.date_of_payment , ( SUM( reservations.cleaning_fee + reservations.processing_fee + reservations.pool_heat_fee + reservations.special_fees + reservations.hoa_fees + reservations.rental_fee + reservations.taxes ) - COALESCE( SUM( reservation_payments.amount_paid ) , 0 ) ) AS sub_total , COALESCE( SUM( reservation_payments.amount_paid ) , 0 ) AS total_paid_to_date , reservations.balance_due_date , ( SELECT GROUP_CONCAT( DISTINCT user_meta.first_name ORDER BY associated_sales_staff.display_order ASC SEPARATOR ", " ) FROM associated_sales_staff JOIN user_meta ON user_meta.user_id = associated_sales_staff.user_id WHERE ( associated_sales_staff.reservation_id = reservations.reservation_id ) ) AS sales_agents FROM reservations JOIN properties ON properties.prop_id = reservations.property_id JOIN reservation_payments ON reservation_payments.reservation_id = reservations.reservation_id WHERE properties.active_for_cleaning_schedule = 1 AND reservations.arrival_date >= "2017-05-15" AND reservations.departure_date <= "2017-05-30" GROUP BY reservations.reservation_id HAVING (sub_total >= 1) ORDER BY total_paid_to_date ASC
Switching from md5 to password_hash
to set custom path for image upload in ckeditor
Which kind of data structure is better? [closed]
Using “terms” and “range” filters together in Elasticsearch
How to use Regex to match PHP time() or microtime() in a string?
Magento 2 - Empty custom widget render
My redirect() function doesn't work using CodeIgniter
How to display actual data from DB
How to use php cURL on local vagrant?
Php help, remote <br /> from addresses (total php noob sorry)
Sabre PHP SOAP client
Correct way to write an IF statement but without an ENDIF?
How to add user id to another table with a submit button
Storing URL in variable
php urlencode and htmlspecialchars a variable inside started function within html <a href>
Cookie detection code not working