0

This SQL query works perfectly well when I remove the AS clause.

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

And when I use AS, it says 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

Could someone please tell me why its not working?

STLDev
  • 5,950
  • 25
  • 36
Navneet Saini
  • 934
  • 4
  • 16
  • 33

2 Answers2

0

Aliases are meant to be put on the columns you select, to :

  • rename them on your output
  • use the alias in the order by or having clause

Source

Understanding your request, you're using an alias for a condition here, what's the point ?

What did you try to do ?

Florian F.
  • 4,700
  • 26
  • 50
  • Actually i want to rank the results. I thought to do something like: `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)` – Navneet Saini Jun 12 '13 at 15:51
  • I don't really get what you're trying to do, if you're trying to sort the results by relevance, you need to include the relevance itself in your selected columns : [Possible duplicate](http://stackoverflow.com/questions/13494460/mysql-fulltext-search-order-by-relevance) – Florian F. Jun 12 '13 at 16:02
0

Change the place of "AS rank"

$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()); 
    }
Jehad Keriaki
  • 545
  • 5
  • 10