0

I'm trying two insert two values (one is a select from another table with a condition) into a table ... but the below returns me an error:

SQL:

INSERT INTO animate_2 (number_records, type) 
     VALUES ((SELECT secty_cd, COUNT(*) 
              FROM securities 
              WHERE secty_cd = 'EQS'
             ), 'eqs'
            );

ERROR 1241 (21000): Operand should contain 1 column(s)

The subquery works though:

mysql> SELECT secty_cd, COUNT(*) FROM securities WHERE secty_cd = 'EQS';
+----------+----------+
| secty_cd | COUNT(*) |
+----------+----------+
| EQS      |    37316 |
+----------+----------+
1 row in set (0.00 sec)

What am I missing?

2 Answers 2

2

You don't need values here, you can simply write your query like following.

INSERT INTO animate_2 (number_records,type) 
SELECT Count(*) , 'eqs'
FROM   securities 
WHERE  secty_cd = 'EQS'
Sign up to request clarification or add additional context in comments.

1 Comment

This is much the better answer.
1

Change this INSERT INTO animate_2 (number_records, type) VALUES ((SELECT secty_cd, COUNT(*) FROM securities WHERE secty_cd = 'EQS'), 'eqs');

To

INSERT INTO animate_2 (number_records, type) VALUES ((SELECT COUNT(*) FROM securities WHERE secty_cd = 'EQS'), 'eqs');

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.