         ae.base_transam_asset_id, Max(ae.created_at) AS asset_event_created_time,  Max(ae.id) AS asset_event_id
       FROM asset_events AS ae
       LEFT JOIN asset_event_types AS aet ON aet.id = ae.asset_event_type_id
-      LEFT JOIN transam_assets AS ta  ON ta.id = ae.transam_asset_id
+      LEFT JOIN transam_assets AS ta  ON ta.id = ae.base_transam_asset_id
       GROUP BY ae.base_transam_asset_id;
 
 DROP VIEW if exists all_assets_recent_asset_events_for_type_view;

        aet.id AS asset_event_type_id, aet.name AS asset_event_name, Max(ae.created_at) AS asset_event_created_time, ae.base_transam_asset_id, Max(ae.id) AS asset_event_id
      FROM asset_events AS ae
      LEFT JOIN asset_event_types AS aet ON aet.id = ae.asset_event_type_id
      LEFT JOIN transam_assets AS ta  ON ta.id = ae.transam_asset_id
      WHERE aet.id IN (
			SELECT id FROM asset_event_types WHERE NAME IN ('Condition', 'Maintenance provider type', 'Service status',
					'Rebuild/rehabilitation', 'Mileage', 'Replacement status', 'Performance restrictions')

      SELECT aet.id AS asset_event_type_id, aet.name AS asset_event_name, Max(ae.created_at) AS asset_event_created_time, ae.base_transam_asset_id, Max(ae.id) AS asset_event_id
      FROM asset_events AS ae
      LEFT JOIN asset_event_types AS aet ON aet.id = ae.asset_event_type_id
      LEFT JOIN transam_assets AS ta  ON ta.id = ae.base_transam_asset_id
      GROUP BY aet.id, ae.base_transam_asset_id;

DROP VIEW if exists all_assets_most_recent_asset_event_view;
