dongpao1873 2018-06-06 08:15
浏览 63
已采纳

显示所有但是避免重复SQL Server中的DB列记录[Moodle] [PHP]

I would like to retrieve and display values in the Database (SQL server). The only problem is that multiple records have the same value in the column. I would basically like cycle through the column and to display a list of all unique values and omit identicals.

$result = $DB->get_records_sql('SELECT column_name FROM table_name WHERE **cycle through column and list all values without duplicates**')

Any help is much appreciated!

  • 写回答

1条回答 默认 最新

  • dpwh11290 2018-06-06 08:16
    关注

    This should do it from the SQL side

    SELECT DISTINCT(column_name) FROM table_name
    

    You could pull all the rows back to the front end and dedupe there, but DISTINCT would probably be better performance.

    SELECT column_name FROM table_name GROUP BY column_name
    

    is another option. Check your execution plan to see if it's any different in how SQL does it for performance.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了