【问题标题】:Hide Duplicate Entries in mySQL隐藏 mySQL 中的重复条目
【发布时间】:2017-08-22 09:54:59
【问题描述】:

我想做一个 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);

【问题讨论】:

  • 在查询开头添加SELECT DISTINCT
  • 您需要阅读DISTINCTGROUP BY 上的SQL 手册。我相信你需要的是后者。

标签: php mysql sql distinct


【解决方案1】:
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 

试试这个

【讨论】:

    【解决方案2】:
    Select id
    From table group by tel
    Having count(user_id)>2
    

    【讨论】:

    • 你应该添加一些文字来解释为什么你认为你的代码回答了这个问题(顺便说一句,它没有)
    猜你喜欢
    • 2018-02-01
    • 1970-01-01
    • 2017-08-15
    • 2016-03-26
    • 2014-08-01
    • 2013-11-17
    • 2020-04-09
    • 1970-01-01
    • 2021-01-22
    相关资源
    最近更新 更多