먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable642( EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,EmployeeName archar(100), EmployeeCompanyNamevarchar(100) ); Query OK, 0 rows affected (0.81 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable642(EmployeeName,EmployeeCompanyName) values('John','Google'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable642(EmployeeName,EmployeeCompanyName) values('Carol','Microsoft'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable642(EmployeeName,EmployeeCompanyName) values('John','Amazon'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable642(EmployeeName,EmployeeCompanyName) values('Carol','Google'); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable642(EmployeeName,EmployeeCompanyName) values('John','Flipkart'); Query OK, 1 row affected (0.14 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable642;
이것은 다음과 같은 출력을 생성합니다 -
+------------+--------------+---------------------+ | EmployeeId | EmployeeName | EmployeeCompanyName | +------------+--------------+---------------------+ | 1 | John | Google | | 2 | Carol | Microsoft | | 3 | John | Amazon | | 4 | Carol | Google | | 5 | John | Flipkart | +------------+--------------+---------------------+ 5 rows in set (0.00 sec)
다음은 특정 회사에서 직원 이름을 가져오는 쿼리입니다 -
mysql> select EmployeeName from DemoTable642 where EmployeeCompanyName="Google" group by EmployeeName;
이것은 다음과 같은 출력을 생성합니다 -
+--------------+ | EmployeeName | +--------------+ | John | | Carol | +--------------+ 2 rows in set (0.00 sec)