duanhongqiong9460 2019-04-28 18:56
浏览 75
已采纳

SQL显示重复条目

I have a SQL code that is pulling information from a database. Here's the code:

$info = "SELECT field_5, record_meta_keywords
FROM cms_custom_database_1
WHERE field_5 > ''
GROUP BY field_5
ORDER BY field_5
DESC LIMIT 10";

The problem is that field_5 has duplicate entries. For example, there are two 868's in that field, but the output is only showing one and not the other. How can I alter this to display all entries and not just one of each number?

  • 写回答

3条回答 默认 最新

  • duankuangxie9070 2019-04-28 18:59
    关注

    You should not use group by without aggregation function

    SELECT field_5, record_meta_keywords
    FROM cms_custom_database_1
    WHERE field_5 > ''
    ORDER BY field_5
    DESC LIMIT 10
    

    if you want distinct value then use distinct

    the use of group by without aggregation function is deprecated in SQL, not allowed (by default) in most recent version of mysql, and produce unpredictable result with other versions (<5.7)

    In your case if you want see all the result then just remove order by

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

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?