Thanks for your reply. I'm building this for a PHP website that's using MySQL.
The table won't be large, it'll only hold 50-100 records, it's for a contest. The reason I want to make it all in one MySQL command is so that if two users try to do it at the same time, only one will be successful. Instead of both doing a MySQL Count(*) and seeing it's below a number (let's say 20), and then both doing an INSERT, when only one should be able to.
I need to limit how many records are in this table, as it's for the prizes, and I just wanted to safeguard against it. Currently I prepopulate the 50-100 rows in the table, and run an UPDATE command, but was hoping to make this more dynamic, as I know there has to be a better way.
So basically I was hoping I could have something like:
INSERT INTO targetTable (key, key, key) VALUES (value, value, value) WHERE (SELECT count(*) FROM targetTable) < 20
I tried that as an example, it didn't work though.