0

Hey guys I was wondering is it possible to use more than 1 INSERT at a time per query? Or does each INSERT have to be done one at a time?

For example I would like to execute these 2 queries as one to save on server resources:

INSERT INTO ExtraStats (date, supportStaff, startEmails, endEmails, emailsAnswered) VALUES ('2012-09-01', '5', '4', '3', '2') ON DUPLICATE KEY UPDATE supportStaff = '5', startEmails = '4', endEmails = '3', emailsAnswered = '2'
INSERT INTO ExtraStats (date, supportStaff, startEmails, endEmails, emailsAnswered) VALUES ('2012-09-2', '5', '6', '7', '8') ON DUPLICATE KEY UPDATE supportStaff = '5', startEmails = '6', endEmails = '7', emailsAnswered = '8'

Is there anyway of combining them? I tried just sticking them in the same query but it didn't like it.

1
  • make a stored procedure and call it. Commented Oct 10, 2012 at 10:01

3 Answers 3

1
INSERT INTO ExtraStats (date, supportStaff, startEmails, endEmails, emailsAnswered) 
VALUES ('2012-09-01', '5', '4', '3', '2') 
ON DUPLICATE KEY UPDATE supportStaff = '5', startEmails = '4', endEmails = '3', emailsAnswered = '2';

('2012-09-2', '5', '6', '7', '8') 
ON DUPLICATE KEY UPDATE supportStaff = '5', startEmails = '6', endEmails = '7', emailsAnswered = '8'
Sign up to request clarification or add additional context in comments.

Comments

1

Yes you can try this

INSERT INTO tbl_name(col1,col2,col3) VALUES ('aaa','bbb','ccc'),('ddd','eee','fff');

or you can put semicolon after first query and continue with second one.

Hope this helps.

Comments

0

seprate by semicolon ";" like :

INSERT INTO ExtraStats (date, supportStaff, startEmails, endEmails, emailsAnswered) 
VALUES ('2012-09-01', '5', '4', '3', '2') ON DUPLICATE KEY UPDATE supportStaff = '5', 
startEmails = '4', endEmails = '3', emailsAnswered = '2';

INSERT INTO ExtraStats (date, supportStaff, startEmails, endEmails, emailsAnswered) VALUES 
('2012-09-2', '5', '6', '7', '8') ON DUPLICATE KEY UPDATE supportStaff = '5', startEmails = 
'6', endEmails = '7', emailsAnswered = '8';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.