oz11 Posted December 29, 2022 Share Posted December 29, 2022 Hey. This is my query... SELECT *, MATCH(terms) AGAINST(?) + MATCH(title) AGAINST(?) + MATCH(url) AGAINST(?) as `rank` FROM links WHERE MATCH(terms) AGAINST(?) OR MATCH(title) AGAINST(?) OR MATCH(url) AGAINST(?) GROUP BY title ORDER BY `rank` DESC LIMIT 34 It works on its own, but i want to limit the "rank" to being a number of 5 only ... so basically i added Quote AND `rank` > 6 though that didnt work...and i got this error.. Quote Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'rank' in 'where clause' in How would I go about doing this? Thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 29, 2022 Share Posted December 29, 2022 You cannot use column aliases in a WHERE clause (they don't exist at that stage of the process). You need to repeat the expression. Quote Link to comment Share on other sites More sharing options...
oz11 Posted December 29, 2022 Author Share Posted December 29, 2022 (edited) How would that look like? Cant seem to get it to work.. tried this: Quote SELECT *, MATCH(terms) AGAINST(?) + MATCH(title) AGAINST(?) + MATCH(url) AGAINST(?) as `rank` FROM links WHERE MATCH(terms) AGAINST(?) OR MATCH(title) AGAINST(?) OR MATCH(url) AGAINST(?) AND (MATCH(terms) AGAINST(?) + MATCH(title) AGAINST(?) + MATCH(url) AGAINST(?)) > 6 GROUP BY title ORDER BY `rank` DESC LIMIT 34 but get "Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number " error.. Edited December 29, 2022 by oz11 Quote Link to comment Share on other sites More sharing options...
Barand Posted December 29, 2022 Share Posted December 29, 2022 You have introduced 3 new placeholders into the query so you need to provide parameter values for them Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.