Insert with SELECT 쿼리의 경우 구문은 다음과 같습니다. -
insert into yourTableName(yourColumnName1,yourColumnName2,yourColumnName3,...N) select yourValue1,yourValue2,yourValue3,......N;
먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable1603 -> ( -> StudentId int, -> StudentName varchar(20), -> StudentMarks int -> ); Query OK, 0 rows affected (0.50 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable1603(StudentId,StudentName,StudentMarks) select 101,'John',45; Query OK, 1 row affected (0.17 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into DemoTable1603(StudentId,StudentName,StudentMarks) select 102,'Adam',76; Query OK, 1 row affected (0.11 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into DemoTable1603(StudentId,StudentName,StudentMarks) select 103,'Bob',67; Query OK, 1 row affected (0.31 sec) Records: 1 Duplicates: 0 Warnings: 0
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select * from DemoTable1603;
이것은 다음과 같은 출력을 생성합니다 -
+-----------+-------------+--------------+ | StudentId | StudentName | StudentMarks | +-----------+-------------+--------------+ | 101 | John | 45 | | 102 | Adam | 76 | | 103 | Bob | 67 | +-----------+-------------+--------------+ 3 rows in set (0.00 sec)