N
N
numb72015-05-26 21:33:18
MySQL
numb7, 2015-05-26 21:33:18

How to find out how many identical records there are in a table?

Good evening!
I have a staff table with the following entries:

id  name         phone
1    Igor          +79098987856
2    Alex           9637677676
3    Andrey        +79655674587
4    Andrey         9655674587
5    Igor           9098987856
6    Ivan           9057688787

the table shows that there are numbers that repeat the last 10 characters, you need to understand how many such numbers are in the database.
How to make a request?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2015-05-26
@numb7

SELECT COUNT(*)
FROM (
  SELECT RIGHT(`phone`, 10) AS `p_number`, COUNT(*) AS `p_number_count`
  FROM `contacts`
  GROUP BY `p_number`
  HAVING `p_number_count` > 1
) AS `dupl_p_numbers`

T
tplus, 2015-05-26
@tplus

SELECT DISTINCT RIGHT(phone, 10) FROM staff;
sqlfiddle.com/#!9/fd862/7

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question