Skip to main content

سریع روش دریافت بزرگترین تاریخ یک کاربر در mysql

[sql]

SELECT * FROM users
WHERE user_id = 2 AND created_at = (SELECT max(created_at) FROM users where user_id = 2)

[/sql]

روش دوم با استفاده از join

[sql]

select t2.* from mlm_reagent_history as t1
INNER JOIN (SELECT max(created_at) lastDate FROM mlm_reagent_history where user_id = 2) as t2 on (t1.created_at = t2.lastDate and t1.user_id = 2 )

[/sql]

روش سوم

[sql]
SELECT * FROM user_log where user_id = 1 order by date_at DESC limit 1
[/sql]

No Comments yet!

Your Email address will not be published.