Use SELECT instead of VALUES to be able to expand the query with a WHERE clause.
EXISTS is a better & faster test than COUNT
INSERT INTO my_table (colname)
SELECT 'foo'
WHERE NOT EXISTS (SELECT * FROM my_table)
More Related Contents:
- get first occurrence of last changed value of a column [closed]
- MySQL – Rows to Columns
- ROW_NUMBER() in MySQL
- multiple query same table but in different columns mysql
- How can I make SQL case sensitive string comparison on MySQL?
- How can I temporarily disable a foreign key constraint in MySQL?
- How to do a batch insert in MySQL
- Count the occurrences of DISTINCT values
- Ordering by the order of values in a SQL IN() clause
- Creating a “Numbers Table” in MySQL
- SQL Selecting from two Tables with inner join and limit [duplicate]
- MySQL Group by SUM
- Set NOW() as Default Value for datetime datatype?
- In SQL, how to select the top 2 rows for each group
- Mysql query to dynamically convert rows to columns on the basis of two columns
- SQL DELETE with JOIN another table for WHERE condition
- mysql trigger stored trigger is already used by statement which invoked stored trigger
- Error Dropping Database (Can’t rmdir ‘.test\’, errno: 17)
- MySQL: How do I join same table multiple times?
- mysql update query with sub query
- What is the difference between the backtick and the square bracket in SQL statements?
- Integrity constraint violation: 1452 Cannot add or update a child row:
- How to insert a file in MySQL database?
- What does SQL Select symbol || mean?
- What is wrong with my SQL here? #1089 – Incorrect prefix key
- #1292 – Incorrect date value: ‘0000-00-00’ [duplicate]
- How to speed up sql queries ? Indexes?
- What happens when I exhaust a bigint generated key? How to handle it?
- is there a length limit to group_concat or another reason why it would not work on a text field
- Deleting a row based on the max value