Syntax error in automatically formed SQL query [closed]

♀尐吖头ヾ 提交于 2019-12-13 09:11:48

问题


I am trying to generate a query for use with a smart search field, ala google suggest.

I can not form the query directly, although I can see what query was made via the logs.

I have posted the query that gets sent, which has a syntax error but I am unsure why.

SELECT DISTINCT IF(guests.passport != '', Concat(guests.passport,
                                                          IF(
                                          guests.lastname !=
                                          ''
                                                   OR guests.passport!= '',
                                                          Concat
                                                          (' (',
                                                          IF(guests.lastname !=
                                                             '',
                                                          guests.lastname,
                                                          '{blank}')
                                                          , ', ',
                                                          IF(
                                                          guests.firstname != ''
                                                             , guests.passport,
                                                          '{blank}')
                                                             , ')'), '')),
                                IF(guests.lastname != ''
                    OR guests.passport!= '', Concat(IF(guests.lastname != '',
                                                    guests.lastname,
                                                    '{blank}'), ', ',
                                                                          IF(
                                             guests.passport!= '',
                                             guests.passport, '{blank}')),
                                ''
                ))              AS display,
                `guests`.`uuid` AS VALUE,
                as              secondary,
                guests.id       AS classname
FROM   guests
WHERE  ( guests.id = 0 )
       AND ( ( guests.firstname LIKE 'b%'
                OR guests.lastname LIKE 'b%'
                OR guests.passport LIKE 'b%' )
              OR (( guests.firstname LIKE 'b%'
                     OR guests.firstname LIKE '% b%'
                     OR guests.lastname LIKE 'b%'
                     OR guests.lastname LIKE '% b%'
                     OR guests.passport LIKE 'b%'
                     OR guests.passport LIKE '% b%' )) )
ORDER  BY IF(guests.passport != '', Concat(guests.passport,
                                              IF(guests.lastname != ''
                                                                OR
                                                 guests.passport!= '',
                                              Concat
                                              (' (',
                                              IF(guests.lastname != '',
                                              guests.lastname, '{blank}')
                                              , ', ',
                                                                        IF(
                                              guests.firstname != ''
                                                       , guests.passport,
                                              '{blank}')
                                                       , ')'), '')),
                    IF(guests.lastname != ''
              OR guests.passport!= '', Concat(IF(guests.lastname != '',
                                              guests.lastname,
                                                                       '{blank}'
                                              ), ', ',
                                       IF(
                                       guests.passport!= '', guests.passport,
                                       '{blank}'
                                       )),
                    ''
          ))
LIMIT  0, 8  

Is there any glaring error in that query?


回答1:


Look at this part:

WHERE () AND

() is not a valid WHERE clause.



来源:https://stackoverflow.com/questions/3152469/syntax-error-in-automatically-formed-sql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!