How can I limit in MySQL maximum rows for the same "user" value?
id | user | data
I think that it's ok, You may want to make a
select count(1) from table where user='XXX'
and check the count before performing the insert.
This could be done by using special "dual" table:
INSERT INTO table (id, user, data)
SELECT 1, 'XXX', 'somedata'
FROM dual
WHERE NOT EXISTS (
SELECT user
FROM t
WHERE user = 'XXX'
GROUP BY user
HAVING COUNT(*) >= 5
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.