How can I do this Fulltext search within an INNER JOIN in MySQL?
I have two tables that I'm joining (in order to get the username from, I'm joining them both on user_id).
Here is my Accounts table structure:
+-----------+------------------+------+-----+-------------------+----------------+
| 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 | |
+-----------+------------------+------+-----+-------------------+-------------开发者_Python百科---+
Here is my Submissions table structure
+-------------+------------------+------+-----+-------------------+----------------+
| 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 | |
+-------------+------------------+------+-----+-------------------+----------------+
Right now, I'm using the following query to get what I need, and it's working fine:
SELECT Submissions.title, Submissions.description, Submissions.timestamp,
Accounts.user_id
FROM `Submissions`
INNER JOIN `Accounts` ON
Submissions.user_id=Accounts.user_id;
Which gives me the following result:
*************************** 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
I'd like to perform a fulltext search on the result set on both the Submissions.title and Submissions.description like:
WHERE MATCH (Submissions.title, Submissions.description) AGAINST (?)
How could I add this to my current query to get the desired result?
first do this
ALTER TABLE Submissions ADD FULLTEXT(title, description);
this will add fulltext search for this two columns
this do this
WHERE MATCH (title, description) AGAINST (’keyword’);
精彩评论