Default_flex Posted April 3, 2009 Share Posted April 3, 2009 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 More sharing options...
0 Antaris Veteran Posted April 3, 2009 Veteran Share Posted April 3, 2009 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 More sharing options...
0 Rohdekill Posted April 4, 2009 Share Posted April 4, 2009 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 More sharing options...
Question
Default_flex
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