Not Amused
Not Amused

Reputation: 962

SELECT and INSERT into another table's field

Is this valid?

SELECT COUNT(*) INTO mydb.table.field FROM sometable WHERE points=30;

If it's not.. anybody who can tell me a similar solution?

Upvotes: 1

Views: 218

Answers (2)

Marc
Marc

Reputation: 16512

No, yours would be exactly like this one

INSERT INTO mydb.table (field)
SELECT Count(*)
FROM   sometable
WHERE  points=30;

Another example with more columns

INSERT INTO mydb.table (Col1, Col2, Col3)
SELECT Col1, Col2, Count(*)
FROM   sometable
WHERE  points=30;

Here you can find many examples.

Upvotes: 2

Samson
Samson

Reputation: 2821

INSERT INTO myTable (field) VALUES 
(SELECT COUNT(*) FROM sometable where points=30)

Upvotes: 1

Related Questions