1

This query doesn't work, but individual queries inserting and selecting only one column do work:

INSERT INTO subdata (reggeduser,completed)
SELECT COUNT(u.email) FROM user AS u,COUNT(a.email) FROM application AS a

My end goal is this:

CREATE EVENT 
ON SCHEDULE EVERY 1 DAY
STARTS '2016-12-12 00:00:00'
DO
INSERT INTO subdata (reggeduser,completed)
SELECT COUNT(u.email) FROM user AS u,COUNT(a.email) FROM application AS a

MySQL version used is 5.6.19-67.0-log.

The error thrown is a simple #1064 Invalid Syntax.

asked Dec 12, 2016 at 20:11

2 Answers 2

1

Here is a way, using variables:

SET @count1=0;
SET @count2=0;
SELECT COUNT(email) INTO @count1 FROM user;
SELECT COUNT(email) INTO @count2 FROM application;
INSERT INTO subdata (reggeduser,completed) VALUES (@count1, @count2);
answered Dec 13, 2016 at 4:24
1
  • The statements need to be inside a transaction at the appropriate isolation level if we want to be sure that the results are consistent. Commented Dec 17, 2016 at 12:53
0
insert into subdata (reggeduser,completed) values
(
 (select count(u.email) from user as u)
 ,(select count(a.email) from application as a)
)

Demo

create table subdata (reggeduser int,completed int);
create table user (email int);
create table application (email int);

insert into subdata (reggeduser,completed) values
(
 (select count(u.email) from user as u)
 ,(select count(a.email) from application as a)
)

1 row(s) affected

answered Dec 12, 2016 at 20:19
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.