2017-08-22 68 views
0

我想創建一個mySQL查詢來選擇所有用戶的信息(姓名,年齡,手機等),不包括「email」或「mobilePhone」上的重複項。在mySQL中隱藏重複條目

所以,我想避免顯示重複條目的用戶誰已經註冊多次。

我的查詢:

$sql = "SELECT tet.id tet_id, tet.firstName tet_fristName, tet.lastName tet_lastName,tet.image tet_image, 
         tet.url tet_url,tet.address tet_address,tet.job tet_job,tet.age tet_age, 
         tet.mobilePhone tet_mobilePhone, tet.homePhone tet_homePhone, tet.email tet_email, 
         tet.date_of_registration tet_date_of_registration, tet.player_id tet_player_id, 
         app.value app_value, app.date app_date 
       FROM `test_players` as tet 
       LEFT JOIN approved_test_players as app on app.player_id=tet.id WHERE app.value IS NULL order by tet.id desc "; 
$result = $conn->query($sql); 
+4

添加'在查詢的開始選擇DISTINCT'。 – KubiRoazhon

+0

您需要閱讀'DISTINCT'和'GROUP BY'上的SQL手冊。我相信這是你需要的後者。 –

回答

-1
Select id 
From table group by tel 
Having count(user_id)>2 
+0

你應該添加一些文字來解釋你爲什麼認爲你的代碼能夠回答這個問題(順便說一下,它沒有) –

0
SELECT DISTINCT tet.firstName as tet_fristName, tet.lastName as tet_lastName,tet.age as tet_age, tet.mobilePhone as tet_mobilePhone, tet.email as tet_email 

FROM `test_players` as tet 

JOIN approved_test_players as app 

ON app.player_id=tet.id 

WHERE app.value IS NULL 

order by tet.id desc 

試試這個