[Solved] How to Remove Duplicates Values from table [duplicate]


Since your screenshot is of phpMyAdmin, I’m going to assume that we’re talking about MySQL here (when asking questions, that’s helpful information as various SQL dialects have different tools that can be used).

If you don’t need id in your results, you can just use DISTINCT:

SELECT
  DISTINCT
    Username,
    Video
FROM
  YourTableName

This returns a list of distinct rows (meaning it considers all columns in determining what is distinct, which is why including id here won’t work).

If you do need to return an ID, you would have to use GROUP BY:

SELECT
  MIN(id) AS id,
  Username,
  Video
FROM
  YourTableName
GROUP BY
  Username,
  Video

Obviously from there, you could select a different ID (MAX(id) for example), or you could select a list of IDs using GROUP_CONCAT (e.g. GROUP_CONCAT(id ORDER BY id ASC) AS id, which will give you a comma-separated list by default unless you change it)

It can also be done using window/analytic functions, which can be a value in very large tables.

Note: When you say “remove all duplicates”, I’m assuming you mean from your results. If you mean literally delete them from the table, you could use this:

DELETE FROM
  YourTableName
WHERE
  id NOT IN(SELECT MIN(id) FROM YourTableName GROUP BY Username,Video)

0

solved How to Remove Duplicates Values from table [duplicate]