Jump to content

SELECT DISTINCT USER ID by unix timestamp


rocoso

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

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

Im trying to get the user_id's  of members according the the latest uploaded photo ordered by the unix timestamp

 

ex:

user_id | upload_date

34          1264401831

80          1264401822

21          1264401813

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.