1
 ID   NAME       Email
 1    John       john@example.com
 2    Mathew     mathew@example.com
 3    John       jon@example.com
 4    Johnson    johns@example.com
 5    Peter      pete@example.com

How can I create a query that will return

1    John       john@example.com
3    John       jon@example.com
4    Johnson    johns@example.com

Ansers like that for Find rows that have the same value on a column in MySQL returns rows with same value. Here I need similar values

Community
  • 1
  • 1
Shoreki
  • 1,057
  • 4
  • 14
  • 33
  • 4
    How do you define similar values? – 1000111 Sep 06 '16 at 08:33
  • I suppose you don't mean something like `select * from ... where NAME like 'john%'`, see: [MySQL Pattern Matching](https://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html)?! Perhaps you mean something like [SQL Similar Data in Column](https://stackoverflow.com/questions/37744220/sql-similar-data-in-column)? – Elijan9 Sep 06 '16 at 08:56
  • Possible duplicate of [sql- Like Query find](http://stackoverflow.com/questions/6626775/sql-like-query-find) – Nikhil Sep 06 '16 at 09:01

1 Answers1

0

Get all the records with similar email first and then only print those records that match the inner condition.

 select * from table_name where email in   (
  select email from table_name 
  group by email 
  having count(*)>1 
)

Tested and working fine.

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78