I have a MySQL table with over 200 values. One of the columns on my table is 'date'. Out of all 200 values there are only 5 unique dates.
我有一个超过200个值的MySQL表。我桌子上的一栏是“约会”。在所有200个值中,只有5个唯一日期。
How can I list out the unique values of the dates and echo them with php. e.g. not getting back 200 instances of dates but just 5.
如何列出日期的唯一值并用php回显它们。例如没有回到200个日期,只有5个。
2 个解决方案
#2
4
SELECT myDate FROM myTable GROUP BY myDate
Or...
要么...
SELECT DISTINCT myDate FROM myTable
DISTINCT
is a nice short hand, but if you ever then want to make use of the query for other purposes, if often constrains you a bit too much. So I prefer the GROUP BY
version.
DISTINCT是一个很好的简写,但是如果你曾经想要将查询用于其他目的,那么通常会让你有点过分。所以我更喜欢GROUP BY版本。
#1
#2
4
SELECT myDate FROM myTable GROUP BY myDate
Or...
要么...
SELECT DISTINCT myDate FROM myTable
DISTINCT
is a nice short hand, but if you ever then want to make use of the query for other purposes, if often constrains you a bit too much. So I prefer the GROUP BY
version.
DISTINCT是一个很好的简写,但是如果你曾经想要将查询用于其他目的,那么通常会让你有点过分。所以我更喜欢GROUP BY版本。