MySQL
 Computer >> コンピューター >  >> プログラミング >> MySQL

動的配列を使用したMySQLLIKEクエリ?


動的配列を使用してLIKEクエリを実装するための構文は、次のとおりです-

select *from yourTableName
   where yourColumnName2 like "%yourValue%"
   order by yourColumnName1 asc
   limit yourLimitValue;

テーブルを作成しましょう-

mysql> create table demo74
   -> (
   -> user_id int not null auto_increment primary key,
   -> user_names varchar(250)
   -> )
   -> ;
Query OK, 0 rows affected (0.67

挿入コマンド-

を使用して、いくつかのレコードをテーブルに挿入します。

mysql> insert into demo74(user_names) values("John Smith1,John Smith2,John Smith3");
Query OK, 1 row affected (0.18

mysql> insert into demo74(user_names) values("John Smith1");
Query OK, 1 row affected (0.15

mysql> insert into demo74(user_names) values("David Smith1");
Query OK, 1 row affected (0.12

mysql> insert into demo74(user_names) values("John Smith1,John Smith2,John Smith3,John Smith4");
Query OK, 1 row affected (0.10

selectステートメントを使用してテーブルのレコードを表示する-

mysql> select *from demo74;

これにより、次の出力が生成されます-

出力

+---------+-------------------------------------------------+

| user_id | user_names                                      |

+---------+-------------------------------------------------+

|       1 | John Smith1,John Smith2,John Smith3             |

|       2 | John Smith1                                     |

|       3 | David Smith1                                    |

|       4 | John Smith1,John Smith2,John Smith3,John Smith4 |

+---------+-------------------------------------------------+

以下は、動的配列を使用したMySQLLIKEクエリです-

mysql> select *from demo74
-> where user_names like "%John Smith1%"
-> order by user_id asc
-> limit 100;

これにより、次の出力が生成されます-

出力

+---------+-------------------------------------------------+

| user_id | user_names                                      |

+---------+-------------------------------------------------+

|       1 | John Smith1,John Smith2,John Smith3             |

|       2 | John Smith1                                     |

|       4 | John Smith1,John Smith2,John Smith3,John Smith4 |

+---------+-------------------------------------------------+

3 rows in set (0.00 sec)


  1. MySQLでSelectクエリを使用して挿入

    SELECTクエリを使用した挿入の場合、構文は次のとおりです- insert into yourTableName(yourColumnName1,yourColumnName2,yourColumnName3,...N) select yourValue1,yourValue2,yourValue3,......N;を選択します。 まずテーブルを作成しましょう- mysql> create table DemoTable1603    -> (    -> StudentId int,    -> Stud

  2. MySQLLIKEをMySQLINとして実装するためのクエリ?

    MySQL IN()のようなクエリを実装するには、LIKE演算子とともにCOUNT()、IF()を使用する必要があります。まずテーブルを作成しましょう- mysql> create table DemoTable    -> (    -> Subject varchar(80)    -> ); Query OK, 0 rows affected (0.58 sec) 挿入コマンド-を使用して、テーブルにいくつかのレコードを挿入します mysql> insert into DemoTable valu