dscdttg4389
2015-12-31 18:31
浏览 30
已采纳

使用PHP distinct从mysql中获取所有唯一数据

I am stuck on fetching unique data from MySql Database by PHP Distinct. I want to fetch all the data from the table but in a particular field 'ccTitle' should remove duplicate entries. My Query is as follows-

"SELECT DISTINCT(*) FROM conferencecreate WHERE ccFlag = 1 AND ccStartingDate >= '$nowTime'"

But it's not working. I discovered Distinct is working individually for a field. Is there another to solve this issue?

Let me know please.

TQ

图片转代码服务由CSDN问答提供 功能建议

我坚持用PHP Distinct 从MySql数据库中获取唯一数据。 我想从表中获取所有数据,但在特定字段“ ccTitle ”中应删除重复的条目。 我的查询如下 -

 “SELECT DISTINCT(*)FROM conferencecreate WHERE ccFlag = 1 AND ccStartingDate> ='$ nowTime'”
   
 
 

但它不起作用。 我发现 Distinct 正在为一个字段单独工作。 还有其他人可以解决这个问题吗?

请告诉我。

TQ

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongtou2097 2015-12-31 20:06
    已采纳

    You are looking for this query:

    SELECT *
    TABLE table
    GROUP BY column
    

    You can write this query with DISTINCT statement like that:

    SELECT DISTINCT ON column *
    FROM table
    
    已采纳该答案
    打赏 评论
  • douyi1939 2015-12-31 18:41

    You are going to have to SELECT DISTINCT for each field you want non-duplicated data ..

    IE

    SELECT DISTICT ON item1,item2 *
    FROM table WHERE something = 'something' 
    
    打赏 评论
  • dongpao1873 2015-12-31 18:58

    Well, finally I found the appropriate answer for my question. Instead of using distinct, group by can be used to solve this issue.

    $q = mysql_query("SELECT * FROM conferencecreate WHERE ccFlag = 1 AND ccStartingDate >= '$nowTime' GROUP BY ccTitle");
    

    It's working for me perfectly.

    Thank you all.

    打赏 评论

相关推荐 更多相似问题