开发者

MySQL Double Order

开发者 https://www.devze.com 2023-04-08 04:03 出处:网络
Is there a better way to write SELECT users.id FROM `users`,`profiles` WHERE users.id = profiles.id &&

Is there a better way to write

SELECT users.id FROM `users`,`profiles` WHERE users.id = profiles.id && 
profiles.zipcode = '$zipcode' && users.id != '1' && users.id != '2'
&& profiles.开发者_运维技巧picture != '' ORDER BY users.last_activity DESC LIMIT 0,11

(The code above is suppose to find all the users with a certain zipcode, and order them by the last_activity timestamp)

Also, is there anyway to sort it by last_activity and gender?


SELECT users.id 
FROM `users`
JOIN `profiles` ON users.id = profiles.id 
WHERE profiles.zipcode = '$zipcode' 
  AND users.id NOT IN (1,2)
  AND profiles.picture != '' 
ORDER BY users.last_activity DESC, users.gender 
LIMIT 0,11


Just add gender:

ORDER BY users.last_activity DESC, users.gender

Note that ordering by the second one (in this case gender) will only happen if two users have the same last_activity value. Consider it a "tie-breaker" ordering.

0

精彩评论

暂无评论...
验证码 换一张
取 消