Select Distinct Query
Posted: Tue Aug 11, 2009 2:14 pm
Hi All,
I have tried to create a list from a table in my database table. I have a simple query that runs when a user logs in to my site that adds the user name and a date/timestamp into two fields (user_name and date).
Now what I want is for a page that I can see to show me the last 15 login's to the site. Now I have managed to get tis query to run fine by using this query:
SELECT * FROM loggedon ORDER BY date DESC LIMIT 0, 15
Now what I want is for the list to only show the latest from each username with a maximum of 15 items displayed as the above shows a list of the last 15 login's but some of these could be from the same user.
Can anyone show me the code that might do this. I have tried using a "SELECT DISTINCT" code but this seems to do nothing. as shown below. This just shows the same information as if the "DISTINCT" was not there.
SELECT DISTINCT user_name, date FROM loggedon ORDER BY date DESC LIMIT 0, 15
Any help???
I have tried to create a list from a table in my database table. I have a simple query that runs when a user logs in to my site that adds the user name and a date/timestamp into two fields (user_name and date).
Now what I want is for a page that I can see to show me the last 15 login's to the site. Now I have managed to get tis query to run fine by using this query:
SELECT * FROM loggedon ORDER BY date DESC LIMIT 0, 15
Now what I want is for the list to only show the latest from each username with a maximum of 15 items displayed as the above shows a list of the last 15 login's but some of these could be from the same user.
Can anyone show me the code that might do this. I have tried using a "SELECT DISTINCT" code but this seems to do nothing. as shown below. This just shows the same information as if the "DISTINCT" was not there.
SELECT DISTINCT user_name, date FROM loggedon ORDER BY date DESC LIMIT 0, 15
Any help???