LEFT JOIN在MATCH(..)之后不起作用.反对(. .布尔模式)



这个查询:

$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 mail .id=mail_views"附近使用正确的语法。lid和mail_views。uid=12 ORDER ' at line 1

为什么?

先JOIN再MATCH

$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)

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

select * from Table1 left join table2 where .....

所以用这个:

           $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);

相关内容

  • 没有找到相关文章

最新更新