MySQL错误,原因不明

时间:2011-08-18 19:58:52

标签: mysql left-join

我现在已经阅读了这个查询大约20分钟,我看不出它有什么问题。

SELECT   SQL_CALC_FOUND_ROWS addressbook_people.first_name,
         addressbook_people.last_name                     ,
         addressbook_people.preferred_name                ,
         addressbook_companies3.name                      ,
         addressbook_people.url                           ,
         addressbook_groups5.name                         ,
         addressbook_people.telephone1                    ,
         addressbook_people.telephone2                    ,
         addressbook_people.telephone3                    ,
         addressbook_people.email1                        ,
         addressbook_people.email2                        ,
         addressbook_people.fax1                          ,
         addressbook_people.fax2                          ,
         root_countries13.name                            ,
         root_territories14.name                          ,
         root_cities15.name                               ,
         addressbook_people.address1                      ,
         addressbook_people.zip_postal1                   ,
         addressbook_people.po_box                        ,
         root_countries19.name                            ,
         root_territories20.name                          ,
         root_cities21.name                               ,
         addressbook_people.address2                      ,
         addressbook_people.zip_postal2
FROM     addressbook_people
WHERE    (
                  (
                           addressbook_people.first_name     LIKE '%a%'
                  OR       addressbook_people.last_name      LIKE '%a%'
                  OR       addressbook_people.preferred_name LIKE '%a%'
                  OR       addressbook_companies3.name       LIKE '%a%'
                  OR       addressbook_people.url            LIKE '%a%'
                  OR       addressbook_groups5.name          LIKE '%a%'
                  OR       addressbook_people.telephone1     LIKE '%a%'
                  OR       addressbook_people.telephone2     LIKE '%a%'
                  OR       addressbook_people.telephone3     LIKE '%a%'
                  OR       addressbook_people.email1         LIKE '%a%'
                  OR       addressbook_people.email2         LIKE '%a%'
                  OR       addressbook_people.fax1           LIKE '%a%'
                  OR       addressbook_people.fax2           LIKE '%a%'
                  OR       root_countries13.name             LIKE '%a%'
                  OR       root_territories14.name           LIKE '%a%'
                  OR       root_cities15.name                LIKE '%a%'
                  OR       addressbook_people.address1       LIKE '%a%'
                  OR       addressbook_people.zip_postal1    LIKE '%a%'
                  OR       addressbook_people.po_box         LIKE '%a%'
                  OR       root_countries19.name             LIKE '%a%'
                  OR       root_territories20.name           LIKE '%a%'
                  OR       root_cities21.name                LIKE '%a%'
                  OR       addressbook_people.address2       LIKE '%a%'
                  OR       addressbook_people.zip_postal2    LIKE '%a%'
                  )
         )
         LEFT JOIN addressbook_companies AS addressbook_companies3
         ON       addressbook_people.company_id = addressbook_companies3.id
         LEFT JOIN addressbook_groups AS addressbook_groups5
         ON       addressbook_people.group_id = addressbook_groups5.id
         LEFT JOIN root_countries AS root_countries13
         ON       addressbook_people.country1 = root_countries13.id
         LEFT JOIN root_territories AS root_territories14
         ON       addressbook_people.territory1 = root_territories14.id
         LEFT JOIN root_cities AS root_cities15
         ON       addressbook_people.city1 = root_cities15.id
         LEFT JOIN root_countries AS root_countries19
         ON       addressbook_people.country2 = root_countries19.id
         LEFT JOIN root_territories AS root_territories20
         ON       addressbook_people.territory2 = root_territories20.id
         LEFT JOIN root_cities AS root_cities21
         ON       addressbook_people.city2 = root_cities21.id
ORDER BY LTRIM(addressbook_people.url)DESC
LIMIT    0, 10

这是我的数据表过滤器的输出。所以忽略我正在寻找'a'

的事实

我使用PHPMyAdmin,当通过Web管理控制台在Query中执行SQL时,我收到以下错误

  

1064 - 您的SQL语法出错;查看手册

     

对应于您的MySQL服务器版本,以便使用正确的语法   靠近'LEFT JOIN addressbook_companies AS addressbook_companies3 ON   addr'在第54行

我检查了这条线,这是我加入的开始。我没有看到问题..有人可以帮忙吗?我从来没有对SQL有任何好处。

1 个答案:

答案 0 :(得分:3)

您需要在JOIN条款

之前执行WHERE