I’ve created a table with an full-text index over 2 columns:
CREATE TABLE players
(
id int NOT NULL,
first_name varchar(25) NOT NULL,
last_name varchar(25) NOT NULL,
team_id int NOT NULL,
PRIMARY KEY (id),
FULLTEXT INDEX full_text_pname (first_name, last_name),
CONSTRAINT p_team_id FOREIGN KEY (team_id) REFERENCES teams (id)
);
Now I want to do a SQL query that recives first_name and last_name and selects the players with those values.
Instead of:
SELECT first_name, last_name, team_id
FROM players
WHERE first_name = % s AND last_name = % s
How can i use match and against?
2
Answers
The syntax for the MATCH() function goes like this:
see documentation
So the query would be something like this:
Fastest This
with
would be faster than using
FULLTEXT
Medium speed for doing an equality match on both columns, you need
with
And it has various issues. It matches Rick, James as well as James, Rick. Probably it would match Jame, Ricks since it treats words as English and plays with endings. Etc.
Slowest This does not run fast: