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
Can't validate reCAPTCHA in PHP form
How to assign read only authority to cells in excel through PHP?
Codeigniter :: how to add a form based on multiple data input when editing the data
SQL UPDATE on page change
Laravel 5.2 uploaded file always null
How to decode this json with foreach
How to open IntelliJ, PhpStorm in a method from an debug external link using file API localhost:63342/api/file/FILENAME:LINE
Validation of one variable can't be equal to other variable not working
How do i limit a value taken from mysql?
Array of objects returns same values
PHP variable into body of php mail
Is there a way to update CMS version from external resource?
how to show div value using jquery?
PHP collecting multiple form data having increment ids
php code to send sms without the manual entry of mobilenumber and message inside the code
Data not saving to an array