×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: SQL
Posted by: Fabian Constien
Added: Nov 25, 2017 6:46 PM
Views: 2
Tags: no tags
  1. SELECT
  2.     `customers`.`id`
  3. FROM
  4.     `customers`
  5.         LEFT JOIN
  6.     `customers_statuses` ON (`customers_statuses`.`customers_id` = `customers`.`id`
  7.         AND `customers_statuses`.`id` = (SELECT
  8.             MAX(`id`)
  9.         FROM
  10.             `customers_statuses`
  11.         WHERE
  12.             `customers_id` = `customers`.`id`))
  13. WHERE
  14.     `customers`.`deleted_timestamp_unix` = 0
  15.         AND `customers_statuses`.`customers_statuses_types_id` = 1
  16.         AND `customers`.`id` = 123;