MAX()

MySQL 函式 Function: MAX()

最大數字資料

SELECT
  *
FROM
  payments
WHERE
  amount = (
    SELECT
      MAX(amount)
    FROM
      payments
  );
SELECT
  *
FROM
  payments
ORDER BY
  amount DESC
LIMIT 1;

每個使用者最新日期資料

SELECT
    a.*
FROM
    messages a
INNER JOIN (
		SELECT name, max(other_col) AS other_col
    FROM messages
		GROUP BY name
) AS b
	ON a.name = b.name
    AND a.other_col = b.other_col

Reference