PDA

View Full Version : SQL Query to get First post of users


induslady
03-14-2015, 01:54 PM
Hello,

Am using the below query to get the post of the users registered during Jan 2015:


SELECT a.title, a.username, a.postid FROM post a, user b
WHERE a.userid = b.userid
AND FROM_UNIXTIME (b.joindate) BETWEEN '2015-01-01' AND '2015-02-01'


From the above query result I would like to get ONLY the first post of each of these users. How do I write the query? Thanks in advance.

kh99
03-14-2015, 02:12 PM
Maybe try adding:
ORDER BY b.joindate LIMIT 1

Edit: oh, wait, that's wrong. It would only work if you were selecting the posts from one user. Now I see why you're asking. :)

Replicant
03-15-2015, 07:05 PM
Try appending GROUP BY a.userid
to the end of the query.