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.
2 Answers 2
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
-
The statements need to be inside a transaction at the appropriate isolation level if we want to be sure that the results are consistent.ypercubeᵀᴹ– ypercubeᵀᴹ2016年12月17日 12:53:14 +00:00Commented Dec 17, 2016 at 12:53
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
lang-sql