MySQL에서 LEFT()를 사용할 수 있습니다. 먼저 −
를 생성해 보겠습니다.mysql> create table DemoTable1428 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20) -> ); Query OK, 0 rows affected (1.05 sec)
insert −
를 사용하여 테이블에 일부 레코드 삽입mysql> insert into DemoTable1428(EmployeeName) values('Chris Brown'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1428(EmployeeName) values('Bob Brown'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1428(EmployeeName) values('John Smith'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1428(EmployeeName) values('David Miller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1428(EmployeeName) values('John Doe'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1428(EmployeeName) values('Carol Johnson'); Query OK, 1 row affected (0.16 sec)
select −
를 사용하여 테이블의 모든 레코드 표시mysql> select * from DemoTable1428;
이것은 다음과 같은 출력을 생성합니다 -
+------------+---------------+ | EmployeeId | EmployeeName | +------------+---------------+ | 1 | Chris Brown | | 2 | Bob Brown | | 3 | John Smith | | 4 | David Miller | | 5 | John Doe | | 6 | Carol Johnson | +------------+---------------+ 6 rows in set (0.00 sec)
다음은 첫 번째 문자로 열 값을 필터링하는 쿼리입니다 -
mysql> select * from DemoTable1428 where left(EmployeeName,1)='J';
이것은 다음과 같은 출력을 생성합니다 -
+------------+--------------+ | EmployeeId | EmployeeName | +------------+--------------+ | 3 | John Smith | | 5 | John Doe | +------------+--------------+ 2 rows in set (0.00 sec)