MySQL WHERE clause usage
P粉403804844
P粉403804844 2023-09-09 20:28:44
0
1
552
MySQL I'm trying to get the Category_id values ​​between 9 and the maximum category id without using the Max function (using a subquery).

I tried the MySQL query given below. It works for the latter part, i.e. it gives category_id up to the maximum category_id. However, it gives all category IDs from the beginning (1), i.e. it does not start from "9".

SELECT columns 
FROM table_name 
WHERE (9 <= category_id <=  (
                 SELECT category_id 
                 FROM table_name 
                 ORDER BY category_id 
                 DESC LIMIT 1 )
       );

P粉403804844
P粉403804844

reply all(1)
P粉221046425

Logically, your query is

SELECT { columns }
FROM table_name 
WHERE 9 <= category_id;

There is no point in using a subquery condition - the column value cannot be greater than the maximum value in this column.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template