PDA

View Full Version : Optimizing a Query to Blog


tsptom
05-14-2010, 04:29 PM
Hi all -

On the homepage of my website (non-VB) I created links to the latest 2 blog entries. The query which finds the latest post does not seem to have a problem, but the query that grabs the second to last post seems to be sluggish.

This one seems OK...
SELECT *
FROM vb_blog
where state = 'visible' and
blogid in (select max(blogid) from vb_blog
where state = 'visible');


This one seems to slow things down...
SELECT *
FROM vb_blog
where state = 'visible' and
blogid in (select max(blogid) -1 from vb_blog
where state = 'visible');
# Query_time: 4 Lock_time: 0 Rows_sent: 1 Rows_examined: 254528


Any suggestions to speed this up?

Thanks!

Deceptor
05-15-2010, 04:50 PM
Why not a query to select both?
select * from vb_blog where state = 'visible' order by blogid desc limit 2;

tsptom
05-15-2010, 06:34 PM
Thanks! Let me give that a shot.