Home » Performance » MySQL » ORDER BY l.linknum DESC limit 5 ?
ORDER BY l.linknum DESC limit 5 ? [message #2517] Mon, 21 January 2008 14:34 Go to next message
pondlife  is currently offline pondlife
Messages: 11
Registered: January 2008
Location: UK
Junior Member
Hi All,

I'm attempting to combine two queries in order to improve performance. I have created the following SQL which works but doesn't do the ORDER BY section correctly - it doesn't extract the 5 most recent linknum's

select l.linknum, l.catagory, l.name, l.link, l.views, count(r.linknum) as RATECOUNT, sum(r.rating)
from links l, ratings r
where l.linknum=r.linknum and l.catagory=64 
group by l.linknum, l.catagory 
order by l.linknum desc limit 5;


Any idea what is wrong with this? The following is the original single query where the ORDER BY works:

select linknum, catagory, name, link, date_entered
    from links where catagory in (64)
    order by linknum desc limit 5;


Many thanks

p
Re: ORDER BY l.linknum DESC limit 5 ? [message #2518 is a reply to message #2517 ] Mon, 21 January 2008 14:36 Go to previous messageGo to next message
pondlife  is currently offline pondlife
Messages: 11
Registered: January 2008
Location: UK
Junior Member
I think I've spotted my error - there may not be matching entries in the 'rating' table...

not sure how to code around this - any advice would be appreciated Smile

Many thanks,

p.
Re: ORDER BY l.linknum DESC limit 5 ? [message #2519 is a reply to message #2517 ] Mon, 21 January 2008 14:44 Go to previous message
pondlife  is currently offline pondlife
Messages: 11
Registered: January 2008
Location: UK
Junior Member
Thought I found the answer but it doesn't look like it's support by my version of MySQL:

mysql> select l.linknum, l.catagory, l.name, l.link, l.views, count(r.linknum) as RATECOUNT, sum(r.rating)
    -> from links l, ratings r
    -> where l.linknum in (select linknum from links where catagory=64 order by linknum desc limit 5)
    -> group by l.linknum;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    2673
Current database: xxxx

ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'


Sad
Previous Topic:Counter as a bottleneck
Next Topic:Best 'Very-Heavy-write' DB config?
Goto Forum:
  


Current Time: Sun Jul 5 22:29:24 EDT 2009

Total time taken to generate the page: 0.01007 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.