Getting DISTINCT ids in MySQL

0

Please login or register to vote for this query.

(click on this box to dismiss)

Return last distinct ids and comments

Korean Language

Q&A for linguists, teachers and students of the Korean language

-- Getting DISTINCT ids in MySQL
-- Return last distinct ids and comments

CREATE TABLE #comments(
  id int,
  review_id int,
  user_id int,
  created datetime,
  comment varchar(30),
  deleted int
);

INSERT INTO #comments VALUES
(1,10,28,'2011-10-12','hi',0),
(2,11,28,'2011-10-13','yo',0),
(3,10,28,'2011-10-15','bye',0);

SELECT id,comment
FROM #comments
WHERE id IN (
    SELECT MAX(id)
    FROM #comments 
    WHERE user_id=28 AND deleted=0
    GROUP BY review_id )
ORDER BY created DESC

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results