Forum Moderators: coopster

Message Too Old, No Replies

select distinct doesn't appear to be working?

         

jamie

10:14 pm on Dec 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i wish to query my news database and return a list of links to previous months in which stories have been written.

this is my code so far:

SELECT DISTINCT month(date_written) as month, year(date_written) as year, UNIX_TIMESTAMP(date) as date
FROM news
WHERE accept = 1
AND month(date_written) IN(1,2,3,4,5,6,7,8,9,10, 11)
AND year(date_written) = 2003
ORDER BY date_written desc

unfortunately this returns an array with 11 entries for november, 10 for october, 13 for september, etc (i.e. the number of stories published in each month) instead of a an array of individual links to each month (11 to be exact ;).

i thought DISTINCT might stop this, but it doesn't? i've been staring at this for quite a while now, and would much appreciate some help if poss.

many thanks

<added> sorry... doh! i just realised distinct can only be used with one record - and actually i only need to select the month, the year nd the date are superfluous...

oh well problem solved ;-)

daisho

3:52 am on Dec 23, 2003 (gmt 0)

10+ Year Member



Distinct works fine. It just doesn't operate on a column level it works on the row level.

You should look into "Group By"

daisho.

jamie

7:28 am on Dec 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thanks daisho :)

that's a nice one!