Here's my table(blog) with all the output shown via SELECT *
I'm trying to select all execpt the highest value in the blogid column
I tried using:
SELECT *
FROM blog
WHERE blogid < MAX(blogid)
ORDER BY createddate DESC
where I hoped it selects all values that is below the max number in blogid but this gets a error "Invalid use of group function".
any help will be appreciated
If you are not using group by, you will need a subquery to calculate the max value:
SELECT *
FROM blog
WHERE blogid < (select MAX(blogid)
from blog)
ORDER BY createddate DESC
you can use not in
SELECT *
FROM blog
WHERE blogid not in ( select MAX(blogid) from blog)
ORDER BY createddate DESC
for selecting max blogid you have to use subquery
You can use HAVING
with the nested query. Aggregates in WHERE
clause may not appear unless it is in a subquery contained in a HAVING
clause or a select list
SELECT *
FROM blog
HAVING blogid < (select MAX(blogid) from blog)
ORDER BY createddate DESC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.