J
J
jorshjorsh952017-05-24 21:29:42
MySQL
jorshjorsh95, 2017-05-24 21:29:42

How to disable selection of duplicate rows?

Hello everyone, I have a table like this:

id | name
1  | Anna
2  | Diana
3  | Sonya
4  | Angela
5  | Daria
6  | Liza

How to display only records with id - 1,2,3,6 (as if excluding those that start with those letters that are already displayed, for example, like here, 4 and 5 id were excluded because there are already records on A and D previously) ?
case not:
SELECT * FROM table GROUP BY name HAVING COUNT(*) =1

?
My head doesn’t boil at all
I can’t think it over at all, please tell me

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-05-24
@jorshjorsh95

SELECT `t2`.*
  FROM (
    SELECT MIN(`id`) AS `id` 
      FROM `table` 
      GROUP BY SUBSTR(`name`, 1, 1)
  ) AS `t1`
  JOIN `table` AS `t2` ON `t2`.`id` = `t1`.`id`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question