MySQL insert into Statement Exercises: Insert rows from country_new table to countries table
MySQL insert into Statement: Exercise-6 with Solution
6. Write a SQL statement insert rows from country_new table to countries table.
Here is the rows for country_new table. Assume that, the countries table is empty.
+------------+--------------+-----------+ | COUNTRY_ID | COUNTRY_NAME | REGION_ID | +------------+--------------+-----------+ | C0001 | India | 1001 | | C0002 | USA | 1007 | | C0003 | UK | 1003 | +------------+--------------+-----------+
Sample Solution:
INSERT INTO countries
SELECT * FROM country_new;
Let execute the above code in MySQL 5.6 command prompt.
Here is the structure of the table:
mysql> SELECT * FROM country_new; +------------+--------------+-----------+ | COUNTRY_ID | COUNTRY_NAME | REGION_ID | +------------+--------------+-----------+ | C0001 | India | 1001 | | C0002 | USA | 1007 | | C0003 | UK | 1003 | +------------+--------------+-----------+ 3 rows in set (0.00 sec)
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:Write a SQL statement to insert 3 rows by a single insert statement.
Next:Write a SQL statement to insert one row in jobs table to ensure that no duplicate value will be entered in the job_id column.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework