开发者

How do I make a MySQL statement from ID to ID

Exa开发者_运维技巧mple I have 500 users and every 50 users manage by one moderator.

Let's say moderator_id = 1 can edit/manage user from user_id 1 until 50. What is the statement should I use?

SELECT * FROM users
  WHERE 
  user_id `what should i use here?` 
  AND 
  moderator_id = '1';

Let me know..


Use the BETWEEN operator, like this:

SELECT *
FROM users
WHERE user_id BETWEEN 1 AND 50
AND moderator_id = '1';


I'm prefer to use an additional column with the moderator_id. In that case you can dynamically change user's set for each moderators without changing anything in the code.

To initially define user's set per moderator use query like that:

UPDATE users
SET moderator_id = 1
WHERE user_id BETWEEN 1 AND 50

To select users by moderator use this query:

SELECT *
FROM users
WHERE moderator_id = 1
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜