按关键词mySQL搜索

时间:2015-08-10 16:26:56

标签: mysql

我正在尝试根据关键字查询表。我的表看起来像:

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| username   | varchar(255) | YES  |     | NULL    |                |
| tweetBody  | varchar(255) | YES  |     | NULL    |                |
| datePosted | varchar(255) | YES  |     | NULL    |                |
| likes      | int(11)      | YES  |     | NULL    |                |
| dislikes   | int(11)      | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

我正在尝试的查询看起来像

SELECT * FROM tweets WHERE tweetBody LIKE'is';

我试图找到包含该作品的所有推文'是'但是我没有得到任何结果。显然,我确实有包含的推文。这是我目前的表格:

+----+----------+----------------------------------------------------------------------------------------------------------------+------------+-------+----------+
| id | username | tweetBody                                                                                                      | datePosted | likes | dislikes |
+----+----------+----------------------------------------------------------------------------------------------------------------+------------+-------+----------+
|  1 | ryan4664 | This is a tweeeeeeet!                                                                                          | 2015/08/09 |     0 |        0 |
|  2 | ryan4664 | Swag chillwave skateboard, roof party messenger bag jean shorts keytar gastropub DIY. Lomo shabby chic liter   | 2015/08/10 |     0 |        0 |
|  3 | ryan4664 | z YOLO slow-carb. Paleo Brooklyn pop-up whatever, hoodie tilde Odd Future semiotics tote b                     | 2015/08/10 |     0 |        0 |
|  4 | ryan4664 | ter distillery church-key meditation chillwave authentic polaroid direct trade. Aesthetic fixie Wes Anderson 9 | 2015/08/10 |     0 |        0 |
+----+----------+----------------------------------------------------------------------------------------------------------------+------------+-------+----------+

1 个答案:

答案 0 :(得分:1)

您需要在like搜索

中添加通配符
SELECT * FROM tweets WHERE tweetBody LIKE '%is%';
  

%匹配任意数量的字符,即使是零字符   _只匹配一个字符。