MySQL: Adding Muliple Values Into Single Column in a Query

First we create a table: CREATE TABLE test_table(id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(10), value VARCHAR(10)); If we want to add Some Values into "name" column only, then we can use this syntax: INSERT INTO test_table (name) values('name1'),('name2'),('namen'); The conclusion is : each values should be enclosed in seperate brackets, which are seperated by a comma.

In case of inserting into multiple columns, we can change it like this:

INESRT INTO test_table (name,value) values('name1','value1'),('name2','value2'),('namen','valuen');

No comments:

Post a Comment

Thank you for commenting. Please keep visiting.