SELECT * FROM floorplan_machines WHERE id IN(41343, 41262, 41267); SELECT * FROM meter WHERE machine_id IN(41343, 41262, 41267) ORDER BY machine_id ASC, date_timestamp DESC; NOTE: This query returns 7 identical records. Need to review the joins. Possibly group by fpm.id, me.date_timestamp SELECT fpm.id as machine_id, fpm.fmaudit_id, fpm.model_id, fpm.floorplan_id, fpm.room_number, fpm.5_year_id, fpm.cpc_black, fpm.cpc_color, fpm.commencement_date, fpm.commencement_black_meter, fpm.commencement_color_meter, fpm.x_position as x_pos, fpm.y_position as y_pos, fpm.budgeted_blk as budgeted_black, fpm.budgeted_color, fpm.serial_number, fpm.ip_address, fpm.vendor_device_id, fpm.under_contract, fpm.is_proposed, fpm.present_floorplan_id, fpm.present_room_number, fpm.local_connection, fpm.present_local_connection, fpm.present_serial_number, fpm.savedname, fpm.save_name_id, fpm.new_vendor_device_id, fpm.present_x_position as present_x_pos, fpm.present_y_position as present_y_pos, fpm.closeout_date, ma.make, ma.model, ma.is_color, coalesce(ma.machine_image,'MissingDeviceImage.png') as machine_image, ma.features, ma_pr.make as present_make, ma_pr.model as present_model, ma_pr.is_color as present_is_color, coalesce(ma_pr.machine_image,'MissingDeviceImage.png') as present_machine_image, ma_pr.features as present_features, fp.id as floorplan_id, fp.building_id, fp.floor_number, bd.id as build_id, bd.building_name, org.id as org_id, org.org_name, org.org_type_id, org.commencement_date as org_commencement_date, DisplayMeterData, MeterDataFeed, org_message, org.cs_pres_black_rate, org.cs_pres_color_rate, cs_prop_black_w_service, cs_prop_black_wo_service, cs_prop_color_w_service, cs_prop_color_wo_service, coalesce(mt.icon_type,'Unknown') as icon_type, coalesce(mt.type_name,'Unknown') as type_name, mt.type as machine_type, mt.CoveredType, coalesce(mt_pr.icon_type,'Unknown') as present_icon_type, coalesce(mt_pr.type_name,'Unknown') as present_type_name, me.black_meter, me.color_meter, me.date_timestamp as meter_timestamp, me_first.black_meter as first_black_meter, me_first.color_meter as first_color_meter, me_first.date_timestamp as first_meter_timestamp, ms.toner, ms.service_needed, dp.dept_name, orgcs.org_id as orgcs_id, orgcs.org_present_black_rate, orgcs.org_present_color_rate, orgcs.org_proposed_black_without_service, orgcs.org_proposed_color_with_service, orgcs.org_proposed_black_with_service, orgcs.org_proposed_color_without_service, fpmc.fmc_costSavingsWithoutService, fpmc.fmc_costSavingsWithService FROM Y2019_floorplan_machines fpm INNER JOIN Y2019_machines ma on fpm.model_id = ma.id INNER JOIN Y2019_machines ma_pr on fpm.present_model_id = ma_pr.id INNER JOIN Y2019_floorplans fp on fpm.floorplan_id = fp.id INNER JOIN Y2019_buildings bd on fp.building_id = bd.id INNER JOIN Y2019_organization org on bd.org_id = org.id INNER JOIN Y2019_machine_types mt on ma.model_type = mt.id INNER JOIN Y2019_machine_types mt_pr on ma_pr.model_type = mt_pr.id LEFT JOIN Y2019_meter me on fpm.id = me.machine_id AND me.date_timestamp = (SELECT max(i.date_timestamp) FROM Y2019_meter i WHERE i.machine_id = fpm.id and black_meter > 0 and date_timestamp < TIMESTAMP('2020-12-08') and date_timestamp > TIMESTAMP('2020-07-01')) LEFT JOIN Y2019_meter me_first on fpm.id = me_first.machine_id AND me_first.date_timestamp = (SELECT min(k.date_timestamp) FROM Y2019_meter k WHERE k.machine_id = fpm.id and k.black_meter > 0 and k.date_timestamp < TIMESTAMP('2020-12-08') and k.date_timestamp >= TIMESTAMP('2020-07-01')) INNER JOIN Y2019_machine_status ms on fpm.id = ms.machine_id AND ms.date_timestamp = (select max(j.date_timestamp) from Y2019_machine_status j where j.machine_id = fpm.id and date_timestamp < TIMESTAMP('2020-12-08') and date_timestamp > TIMESTAMP('2020-07-01')) INNER JOIN Y2019_department dp on fpm.dept_id = dp.id INNER JOIN Y2019_org_service_rates orgcs on org.id = orgcs.org_id INNER JOIN floorplan_machines_calculations fpmc on fpm.id = fpmc.fmc_id where fpm.id = 3073;