1

How can I count total rows from different tables and insert them into a column of a result table. In MySQL

Insert into hospitals(total_case)
Select count(*)
Id, count (id)
From Islamabad 
thanasisp
  • 5,855
  • 3
  • 14
  • 31
ali
  • 11
  • 3
  • 1
    here you're fetching 2 column but trying to insert in single column. That would be an issue. – Dark Knight Sep 18 '20 at 13:18
  • 1
    Does this answer your question? [INSERT with SELECT](https://stackoverflow.com/questions/5391344/insert-with-select) – Kars Sep 19 '20 at 10:56

1 Answers1

0

Number of columns in INSERT INTO statement should match with number of columns selected in SELECT clause.

You have selected two columns count(*) Id, count (id) but want to insert in single column total_case which would create an error.

INSERT INTO hospitals (total_case)
SELECT COUNT(id)
FROM Islamabad;
Dark Knight
  • 6,116
  • 1
  • 15
  • 37