Jump to content

Recommended Posts

Hi

 

Im trying to select distinct user_id by unix timestamp.

Im storing unix timestamps in the DB ex: 1264401846

 

I just want the user_id's of the most recent uploaded photos

 

This is what i have so far but it returns duplicates

$datetime = mktime();

 

$sql="SELECT DISTINCT(user_id), upload_date FROM image_albums WHERE FROM_UNIXTIME(upload_date) < FROM_UNIXTIME(".$datetime.") ORDER BY upload_date DESC LIMIT 3";

 

HELP??

 

DISTINCT is not a function. It does not apply to a single column you select. It applies to all the columns you select. It simply removes duplicate rows from the result set.

 

What exactly are you trying to do, please show an example of some data and the expected results.

 

 

Actually, that's not much of an example to show what you are trying to do. However, I'll guess that you want the latest row for each user. If so, see this link - http://dev.mysql.com/doc/refman/5.1/en/example-maximum-column-group-row.html

Thanks PFMaBiSmAd!!  8)

 

This is working

SELECT s1.user_id,FROM_UNIXTIME(s1.upload_date) FROM image_albums s1
LEFT JOIN image_albums s2 ON s1.user_id = s2.user_id AND FROM_UNIXTIME(s1.upload_date) < FROM_UNIXTIME(s2.upload_date)
WHERE s2.user_id IS NULL ORDER by FROM_UNIXTIME(s1.upload_date) DESC LIMIT 8

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.