dre75230 2018-03-07 13:00
浏览 64
已采纳

过滤掉实际上不重复MySQL的重复项

So I have a database in which I have to search for duplicate records and it's going pretty well so far. However, since the data That I currently am using to check for duplicates has quite a few records where it is a null value. Therefore it considers them duplicates of each other while they actually aren't.

here is an example of my problem (this is not the actual representation of the database! it is merely an example)

example:

Real duplicate:

--------------------------------------------------
| id | Storename | Location | coordinates |
--------------------------------------------------
|  1 | bigPharma | Amsterdam| 51,12345    |
--------------------------------------------------
|  2 | bigPharma | Amsterdam| 51,12345    |
--------------------------------------------------

Fake duplicate:

--------------------------------------------------
| id | Storename | Location | coordinates |
--------------------------------------------------
|  3 | Jumbo     |Loosdrecht|             |
--------------------------------------------------
|  4 | Lidl      | Limburg  |             |
--------------------------------------------------

You see that with the one you have coordinates and with the other they are empty but not a NULL value.

Question: So what do I need to do to make my program detect these kinds of discrepancies?

Example of my code:

  function winkel_duplicates_algemeen() {
   global $conn;

   $statement = $conn->prepare('SELECT
     u.winkel_id,
     u.winkel_filiaal_id,
     u.winkel_naam,
     u.winkel_filiaal_nr,
     u.winkel_straat,
     u.winkel_huisnummer,
     u.winkel_toevoeging,
     u.winkel_postcode,
     u.winkel_plaats,
     u.winkel_lat,
     u.winkel_lng,
     u.winkel_actief
   FROM
     winkel_adresgegevens u
         INNER JOIN
     (SELECT
         winkel_lat, winkel_lng, COUNT(*)
     FROM
         winkel_adresgegevens
     GROUP BY winkel_lat, winkel_lng
     HAVING COUNT(*) > 1) temp ON temp.winkel_lat = u.winkel_lat
         AND temp.winkel_lng = u.winkel_lng
   ORDER BY winkel_lat, winkel_lng, winkel_filiaal_id;');

  $statement->execute();

  return $statement;
}
  • 写回答

4条回答 默认 最新

  • dongmu5246 2018-03-09 08:03
    关注

    Hello people I have found a working solution to my problem!

    column.name IS NOT NULL AND column.name != ""
    column.name IS NOT NULL AND column.name != ""
    

    Feel free to use it whenever and thank you all for your input!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误