2013-06-12 175 views
0

當我刪除AS子句時,此SQL查詢工作得非常好。MySQL中的語法錯誤:AS語句

$query = "SELECT bd_brushname FROM tbl_brushdescription WHERE MATCH(bd_brushname, bd_brushdescription) AGAINST ('brushes' IN BOOLEAN MODE) AS rank"; 
    $sqlquery = mysql_query($query); 
    if($sqlquery === FALSE){ 
     die(mysql_error()); 
    } 

當我用AS,它說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 'AS rank' at line 1

可能有人請告訴我,爲什麼它不工作?

+1

可能重複[MySQL作爲在WHERE語句(http://stackoverflow.com/questions/4611451/mysql-as-in-where-的地方聲明) –

回答

0

別名意味着要投入你所選擇的列,以:

  • 將其重命名你的輸出
  • order byhaving條款

Source

中使用別名

瞭解您的請求,您在此處使用別名來表示條件,有什麼意義?

你試圖做什麼?

+0

其實我想排名的結果。我想這樣做:'SELECT bd_brushname FROM tbl_brushdescription WHERE MATCH(bd_brushname,bd_brushdescription)AGAINST('brushes'IN BOOLEAN MODE)AS rank WHERE MATCH(bd_brushname,bd_brushdescription)AGAINST('brushes'IN BOOLEAN MODE)' –

+0

I don如果你試圖按照相關性對結果進行排序,那麼你需要將相關性本身包含在你選擇的列中:[可能的重複](http://stackoverflow.com/questions)/13494460/MySQL的-全文搜索順序逐相關性) –

0

變化的 「秩」

$query = "SELECT bd_brushname AS rank FROM tbl_brushdescription WHERE MATCH(bd_brushname, bd_brushdescription) AGAINST ('brushes' IN BOOLEAN MODE)"; 
    $sqlquery = mysql_query($query); 
    if($sqlquery === FALSE){ 
     die(mysql_error()); 
    }