简体   繁体   English

MYSQL SELECT DISTINCT在PHP中不是唯一的,但在数据库中是唯一的

[英]MYSQL SELECT DISTINCT is not distinct in the PHP, but is distinct in the database

I have another problem with sql queries running as I expect in PHPMyadmin, but when I add the sql to my PHP script, it does not work as expected. 我在PHPMyadmin中按预期运行sql查询时遇到另一个问题,但是当我将sql添加到我的PHP脚本中时,它无法按预期工作。

This is the formula of my sql: 这是我的SQL的公式:

select DISTINCT 
        table1.id AS ID,
        table1.title AS Title,
        table1.startdate AS StartDate,
        table1.enddate AS EndDate,
        table1.type AS Type,
        table2.image AS ImagePath
        table3.colour AS Colour
        FROM table1
        table1 LEFT JOIN table2 table2 ON table1.id = table2.id
               LEFT JOIN table3 table3 ON table1.id = table3.id
        WHERE Type LIKE 'E' AND StartDate >= DATE(NOW()) AND EndDate >= DATE(NOW()) 
        ORDER BY StartDate ASC

I get 23 results returned in PHPMyadmin which is correct - but when I add the sql to my PHP and run it, I get duplicate entries and I am not sure what I am doing wrong. 我在PHPMyadmin中返回了23个正确的结果-但是,当我将sql添加到我的PHP中并运行它时,我得到重复的条目,而且我不确定自己在做什么错。

Any ideas? 有任何想法吗?

It would appear that it is not the SQL that is the issue - We have inherited a drupal site and there is a function that seems to executing more than once, causing the sql to be executed multiple times. 似乎不是SQL才是问题所在-我们继承了一个drupal站点,并且有一个函数似乎执行了多次,从而导致该SQL被多次执行。

Better get digging to find out the issue! 最好深入研究以找出问题所在!

Thanks anyway guys! 谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM