简体   繁体   中英

sql_query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

I am new to mysql and sphinx and trying hands-on before heading to live project. I want to apply UNION ALL on 2 tables in sphinxsearch. Below is my sql query

sql_query               = \
                (SELECT users.id AS uid, users.fname, users.lname, users.email \
                FROM users) \
                UNION ALL \
                (SELECT documents.id AS diid, documents.description \
                FROM documents);

but when I go for index command, its shows me error

ERROR: index 'my_search': sql_query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM users) UNION ALL SELECT documents.id AS dii' at line 1 (DSN=mysql://root:***@localhost:3306/testsphinx).

I think the two 'sub-queries' in a UNION should have the SAME schema. Ie the database is going to produce one resultset with columns. Its just the rows would come from different tables.

If want to index two tables in SPhinx - in one index, possibly best to use multiuple sources

source users {
...
sql_query               = \
                SELECT users.id AS uid, users.fname, users.lname, users.email \
                FROM users
...
}

source documents {
...
sql_query               = \
                SELECT documents.id AS diid, documents.description \
                FROM documents
...
}

index index1 {
   source users 
   source documents 
   path = /var/sphinx/index1
....
}

But can make them too seperate indexes as well. That gives MOST flexiblity, CAN query them together if want

sphinx> SELECT * from users,documents WHERE MATCH('toad') 

or can query them individually too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question my sql :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0'' at line 1 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''leave'' You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*' at line 5 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 4 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= WHERE You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM