INSERT INTO table_name(field1,field2,field3,field4) values('value1','value2','value3','value4')
Here the order of the fields need not be same as order in our MySQL table but the order we are specifying by saying the field names, that order we must maintain for values. We have to take care of the fields where we have given NOT NULL or any other such requirements. Any violation of the field structure will generate an error message.
CREATE TABLE t1 (id int(11) NOT NULL default '0',name1 varchar(10) NOT NULL default '') TYPE=MyISAM;
Adding records to the table t1
INSERT INTO t1 VALUES (1, 'one1');
INSERT INTO t1 VALUES (2, 'two1');
INSERT INTO t1 VALUES (3, 'three1');
INSERT INTO t1 VALUES (4, 'four'),(5,'five'),(6,'six');
We have added three records using one insert command.
INSERT INTO student2 SELECT * FROM student
This query will copy all records from student to student2 table.
INSERT INTO student2 SELECT * FROM student WHERE class='Four'
Only students of class four are copied to student2 table.
insert into table1 (table1.column1) SELECT table2.column1 from table2
MySQL auto increment field
sagar | 08-04-2009 |
i want to simple insert,update/edit, query in php |
kiran | 14-12-2009 |
I want 2 insert record in excelsheet thru oledb jet4.0 bt condiotion is no duplicate records |
Regalla Naresh Reddy | 13-01-2010 |
Hi, I have 2 tables named as PMOCreationTable and FinanceTable. PMOCreationTable has one column named as InstanceID which is unique. I have the same column in the FinanceTable. FinanceTable also have some additional columns. So i want to copy the data of InstanceID column from PMOCreationTable to FinanceTable at the same time i want insert some values in to the FinanceTable. Means at the same time i need to get the one column data from other table and insert some values in to the table along with it. Can you provide me a solution for this. Its very important for me. |
smo | 13-01-2010 |
You can update 2nd table but I don't thik you can use another insert command in one go. |
ijah | 08-02-2010 |
hi, i need help..i want to populate my date table according to the days based on 2006 year calendar. i will start from 1 until 365 days and 1 jan 2006 falls on Sunday. How to insert all the days starts from Sunday (1 jan 2006) to Saturday ( 7 jan 2006) and after that the day will start over again with sunday (8 jan 2006)? this should occur until the last day of 2006 which is 31/12/2006. thanks |
smo | 09-02-2010 |
First you populate one column with incremental date for all 365 days. Then use the dayofweek function to update/add another field with weekdays. There can be a better way of doing this also. |
abhishek | 02-06-2010 |
how to insert values in table multiple times using a single insert command |
Mehmood Khan | 08-06-2010 |
hello sir .. i want to perform a opertion like this when i click show button all records are to be showd and same update ,insert in etc.... in php mysql |
binnie | 12-08-2010 |
How to insert records into 2 or more tables using only one query? |
pakoy | 10-02-2011 |
Hi Sir.. i want to perform operation like this i want to view GROUP BY date and VIEW all under that date |