开发者

Is it possible to do a find function in SQL?

开发者 https://www.devze.com 2023-02-13 14:00 出处:网络
I\'m looking for something like this: Let\'s say we have a string.. $chk=\"pie\"; And we want to find something in the database with the string $chk in it..

I'm looking for something like this:

Let's say we have a string..

$chk="pie";

And we want to find something in the database with the string $chk in it..

Say the database looks like this:

username realna开发者_高级运维me
123pieo  Bob
ilikepie Carl
wat      Tom

Can I select the ones that contain $chk in them some how?


This will select any rows that contain "pie" in the username.

SELECT * FROM tablename WHERE username LIKE "%pie%"


Take a look at MySQL's pattern matching.

From http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html.

To find names beginning with “b”:

mysql> SELECT * FROM pet WHERE name LIKE 'b%';
+--------+--------+---------+------+------------+------------+
| name   | owner  | species | sex  | birth      | death      |
+--------+--------+---------+------+------------+------------+
| Buffy  | Harold | dog     | f    | 1989-05-13 | NULL       |
| Bowser | Diane  | dog     | m    | 1989-08-31 | 1995-07-29 |
+--------+--------+---------+------+------------+------------+
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号