MATCH(...)反对后,LEFT JOIN不起作用(...在BOOLEAN模式下)

时间:2013-01-12 17:41:40

标签: mysql left-join match-against

此查询:

$user_mail_all=mysql_query("SELECT * 
FROM `mailing` WHERE MATCH (resp) 
AGAINST ('$user_resp' IN BOOLEAN MODE) 
OR `cor`='$username' ORDER BY `id` DESC  LIMIT ".$start.",".$per_page )

运行良好,但下一个查询:

$user_mail_all=mysql_query("SELECT * 
FROM `mailing`WHERE MATCH (resp) 
AGAINST ('$user_resp' IN BOOLEAN MODE) 
OR `cor`='$username' 
LEFT JOIN `mail_views` 
ON mailing.id=mail_views.lid 
AND mail_views.uid=".$_SESSION['uid']." 
ORDER BY `id` DESC  LIMIT ".$start.",".$per_page)

导致错误:

  

您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在“LEFT JOIN mail_views on mailing.id = mail_views.lid AND mail_views.uid = 12 ORDER'第1行附近使用正确的语法

为什么呢?

2 个答案:

答案 0 :(得分:1)

首先加入然后匹配

$user_mail_all=mysql_query("SELECT * 
FROM `mailing`
LEFT JOIN `mail_views` 
ON mailing.id=mail_views.lid 
WHERE MATCH (resp) 
AGAINST ('$user_resp' IN BOOLEAN MODE) 
OR `cor`='$username' 
AND mail_views.uid=".$_SESSION['uid']." 
ORDER BY `id` DESC  LIMIT ".$start.",".$per_page)

答案 1 :(得分:0)

在您的查询左连接实现中是错误的......它应该是:

Table1 左连接 table2中选择*,其中.....

所以请使用:

           $user_mail_all=
                mysql_query(
                             "SELECT * 
                                FROM `mailing`
                           LEFT JOIN `mail_views` 
                                 ON ( mailing.id=mail_views.lid 
                                     AND mail_views.uid=".$_SESSION['uid']".)
                              WHERE MATCH (resp) 
                                    AGAINST ('$user_resp' IN BOOLEAN MODE) 
                                 OR `cor`='$username'
                           ORDER BY `id` DESC  LIMIT ".$start.",".$per_page);