MySQL: Is it possible to “INSERT if number of rows with a specific value is less than X”?
问题 To give a simple analogy, I have a table as follows: id (PK) | gift_giver_id (FK) | gift_receiver_id (FK) | gift_date Is it possible to update the table in a single query in such a way that would add a row (i.e. another gift for a person) only if the person has less than 10 gifts so far (i.e. less than 10 rows with the same gift_giver_id)? The purpose of this would be to limit the table size to 10 gifts per person. Thanks in advance. 回答1: "And would that also be, 'otherwise, update the fields