• 0

Mysql return all rows except last


Question

I've been trying to come up with a way to write this in mysql but its pretty hard. Wanted to know if any of you guys would help out?

this is the closest i've gotten.

SELECT * FROM blog WHERE "id" NOT IN (SELECT id FROM blog ORDER BY id DESC LIMIT 1) LIMIT 1.

IT would work but mysql doesn't support LIMIT in sub queries.

thanks.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Lol, your title and query seem to be different :p

I don't quite get what you're trying to do, you subquery looks like it is trying to return 1 item, and then you are trying to select one other item where it doesnt exist in the result set of the subquery. Thats non-sensical. If that were a valid query, it would always return the first record, because you are not ordering the outer query, and only selecting the top item.

What is it you are actually trying to do?

Link to comment
Share on other sites

  • 0

declare @max as int

set @max = (select max(ID) from [blog])

select * from [blog] where ID <@max

if all you wanted was the last entry then the last line would be:

select * from [blog] where ID = @max

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.