我有两个表正在加入(为了获取用户名,我在user_id上加入它们)。
以下是我的帐户表格结构:
+-----------+------------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------------+------+-----+-------------------+----------------+
| user_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(20) | NO | | NULL | |
| email | varchar(128) | YES | | NULL | |
| timestamp | timestamp | YES | | CURRENT_TIMESTAMP | |
| hashed_pw | varchar(255) | YES | | NULL | |
| active | char(32) | YES | | NULL | |
+-----------+------------------+------+-----+-------------------+----------------+
以下是我的提交表格结构
+-------------+------------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+-------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| title | varchar(255) | NO | MUL | NULL | |
| description | varchar(255) | YES | | NULL | |
| source | varchar(255) | NO | | NULL | |
| category | varchar(64) | NO | | NULL | |
| user_id | int(10) unsigned | NO | MUL | NULL | |
| submit_ip | int(4) unsigned | NO | | NULL | |
| timestamp | timestamp | NO | MUL | CURRENT_TIMESTAMP | |
| thumbnail | varchar(255) | YES | | NULL | |
+-------------+------------------+------+-----+-------------------+----------------+
现在,我正在使用以下查询来获取我需要的内容,并且它运行正常:
SELECT Submissions.title, Submissions.description, Submissions.timestamp,
Accounts.user_id
FROM `Submissions`
INNER JOIN `Accounts` ON
Submissions.user_id=Accounts.user_id;
这给了我以下结果:
*************************** 1. row ***************************
title: IJL that one of the men who discovered the stratosphere had a very unfortunate
name.
description:
timestamp: 2011-04-27 01:43:54
user_id: 8
*************************** 2. row ***************************
title: IJL that nuclear reactors actually glow blue.
description: Testing the description out on this one
timestamp: 2011-04-27 02:05:12
user_id: 8
我想在Submissions.title和Submissions.description上对结果集执行全文搜索,如:
WHERE MATCH (Submissions.title, Submissions.description) AGAINST (?)
如何将此添加到我当前的查询中以获得所需的结果?
答案 0 :(得分:0)
首先这样做
ALTER TABLE Submissions ADD FULLTEXT(title, description);
这将为这两列添加全文搜索
这样做
WHERE MATCH (title, description) AGAINST (’keyword’);