Jump to content

Select Distinct Query


DAVID_ASC

Recommended Posts

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???

Link to comment
https://forums.phpfreaks.com/topic/169813-select-distinct-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.