# ORDER BY l.linknum DESC limit 5 ?

**URL:** <https://forums.percona.com/t/order-by-l-linknum-desc-limit-5/604>\
**Category:** Other MySQL® Questions\
**Created:** [January 21, 2008, 2:04pm UTC](https://forums.percona.com/t/order-by-l-linknum-desc-limit-5/604 "2008-01-21T14:04:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pondlife](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@pondlife](https://forums.percona.com/u/pondlife)\
**Post date:** [January 21, 2008, 2:04pm UTC](https://forums.percona.com/t/order-by-l-linknum-desc-limit-5/604/1 "2008-01-21T14:04:47Z")

</div>

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 rwhere 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

---

<div class="post-metadata">

**Author:** ![pondlife](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@pondlife](https://forums.percona.com/u/pondlife)\
**Post date:** [January 21, 2008, 2:06pm UTC](https://forums.percona.com/t/order-by-l-linknum-desc-limit-5/604/2 "2008-01-21T14:06:00Z")

</div>

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 )

Many thanks,

p.

---

<div class="post-metadata">

**Author:** ![pondlife](https://avatars.discourse-cdn.com/v4/letter/p/a88e4f/32.png) [@pondlife](https://forums.percona.com/u/pondlife)\
**Post date:** [January 21, 2008, 2:14pm UTC](https://forums.percona.com/t/order-by-l-linknum-desc-limit-5/604/3 "2008-01-21T14:14:01Z")

</div>

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 awayNo connection. Trying to reconnect…Connection id: 2673Current database: xxxxERROR 1235 (42000): This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery’

(
