Samar Rizvi Samar Rizvi - 7 months ago 10
SQL Question

Mysql syntax error when doing a full text serach

Here is mysql query that I am using for the full-text search:

SELECT * FROM subscribers
WHERE MATCH (full_name,phone,email,company,url,group)
AGAINST ('samar' IN NATURAL LANGUAGE MODE);


And here is error that I recieve:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'group)
AGAINST ('database' IN NATURAL LANGUAGE MODE)
LIMIT 0, 25' at line 2

Answer

In MySQL, group is a reserved keyword. If you actually named a column after this (you shouldn't have), then you can avoid this error by escaping it:

SELECT * FROM subscribers
WHERE MATCH (`full_name`, `phone`, `email`, `company`, `url`, `group`)
AGAINST ('samar' IN NATURAL LANGUAGE MODE);

I escaped every column in my answer because it looks consistent, but I believe you should only need to escape group.

Comments