1

I have two queries:

SELECT `u`.*, `ic`.*  FROM `users` `u`,
  JOIN `invitation_codes` `ic`
    ON `ic`.user_id = `u`.id
 WHERE `u`.`mail` = :mail AND `is_deleted` = 0;

AND

SELECT *  FROM `users`,
  (SELECT `level`  FROM `point_thresholds` WHERE :points BETWEEN `low_threshold` AND `top_threshold`) AS level,
  (SELECT `level_name` FROM `point_thresholds` WHERE :points BETWEEN `low_threshold` AND `top_threshold`) AS level_name
  WHERE `mail` = :mail AND `is_deleted` = 0;

Now I am trying to combine this queries into one:

SELECT `u`.*, `ic`.*  FROM `users` `u`,
  (SELECT `level`  FROM `point_thresholds` WHERE :points BETWEEN `low_threshold` AND `top_threshold`) AS level,
  (SELECT `level_name` FROM `point_thresholds` WHERE :points BETWEEN `low_threshold` AND `top_threshold`) AS level_name
  JOIN `invitation_codes` `ic`
  ON `ic`.`user_id` = `u`.`id`
  WHERE `u`.`mail` = :mail AND `is_deleted` = 0;

Unfortunately he gets the error #1054 - Unknown column 'u.id' in 'on clause' and I have no idea why, theoretically everything looks quite OK. Someone would be able to and would like to suggest what I am doing wrong?

Shadow
  • 33,525
  • 10
  • 51
  • 64
Elijah
  • 422
  • 2
  • 8
  • Sample data, desired results, and what you want the overall query to do would all help. – Gordon Linoff Sep 21 '21 at 22:45
  • Read https://dev.mysql.com/doc/refman/8.0/en/join.html, near the bottom of the page where it starts, "JOIN has higher precedence than the comma operator." – Bill Karwin Sep 21 '21 at 22:57

0 Answers0