sql - Mysql: obtaining n elements of a given subset of N records -
my goal n "best" items given subset of n registers of table. have table called recipes, , want 5 best recipes (the liked) of last, let's say, 50 recipes uploaded. clarifying, this:
select * `recipes` id in (select id `recipes` order created desc limit 50) order likes desc limit 5
but limit can't used in subquery. so, what's simplest way accomplish that? in advance.
you can same join
select * `recipes` r1 bring together (select id `recipes` order created desc limit 50) r2 on r1.id =r2.id order r1.likes desc limit 5
mysql sql database
No comments:
Post a Comment