Computer >> 컴퓨터 >  >> 프로그램 작성 >> MySQL

열 값의 두 문자열 중 하나와 일치하는 MySQL 쿼리

<시간/>

이를 위해 OR 조건과 함께 LIKE 연산자를 사용할 수 있습니다.

먼저 테이블을 생성하겠습니다 -

mysql> create table DemoTable762 (Title text);
Query OK, 0 rows affected (0.54 sec)

삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -

mysql> insert into DemoTable762 values('Introduction to Java');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable762 values('MySQL is a RDBMS');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable762 values('Data Structure and Algorithm in Java');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable762 values('Data Structure and Algorithm in C and C++');
Query OK, 1 row affected (0.18 sec)

select 문을 사용하여 테이블의 모든 레코드 표시 -

mysql> select *from DemoTable762 ;

그러면 다음과 같은 출력이 생성됩니다. -

+-------------------------------------------+
| Title                                     |
+-------------------------------------------+
| Introduction to Java                      |
| MySQL is a RDBMS                          |
| Data Structure and Algorithm in Java      |
| Data Structure and Algorithm in C and C++ |
+-------------------------------------------+
4 rows in set (0.00 sec)

다음은 "MySQL" 또는 "Algorithm" 두 문자열 중 하나를 일치시키는 쿼리입니다. -

mysql> select *from DemoTable762 where Title LIKE '%MySQL%' or Title LIKE '%Algorithm%';

그러면 다음과 같은 출력이 생성됩니다. -

+-------------------------------------------+
| Title                                     |
+-------------------------------------------+
| MySQL is a RDBMS                          |
| Data Structure and Algorithm in Java      |
| Data Structure and Algorithm in C and C++ |
+-------------------------------------------+
3 rows in set (0.00 sec)