SELECT a.userid, a.username, FROM_UNIXTIME(b.regdate) AS BuyDate, FROM_UNIXTIME(b.expirydate) AS ExpiryDate FROM user a INNER JOIN subscriptionlog b ON a.userid = b.userid WHERE b.expirydate > UNIX_TIMESTAMP() order by b.expirydate desc