2016-09-06 46 views
0
ID NAME  Email 
1 John  [email protected] 
2 Mathew  [email protected] 
3 John  [email protected] 
4 Johnson [email protected] 
5 Peter  [email protected] 

如何創建一個查詢,將返回SQL - 尋找有類似值的行的列

1 John  [email protected] 
3 John  [email protected] 
4 Johnson [email protected] 

Ansers一樣,對於具有相同的價值Find rows that have the same value on a column in MySQL返回行。這裏我需要類似的值

+3

你如何定義相似的值? – 1000111

+0

我想你並不是指像'select * from ...'這樣的名字,比如'john%'',請參閱:[MySQL Pattern Matching](https://dev.mysql.com/doc/refman/5.7/)烯/圖案matching.html)? 也許你的意思是像[列中的SQL相似數據](https://stackoverflow.com/questions/37744220/sql-similar-data-in-column)? – Elijan9

+0

可能重複的[sql- Like Query find](http://stackoverflow.com/questions/6626775/sql-like-query-find) – Nikhil

回答

1

先獲取所有具有類似電子郵件的記錄,然後只打印符合內部條件的記錄。

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

測試和工作正常。

+0

工作!謝謝丹尼爾 – Shoreki