AdRock
AdRock

Reputation: 3096

Getting the last 5 records of a joined query

I have a query that does what i want joining table but i need it to change sligtly so i can use it for something else.

I need to get the last 5 records so i should be using the max function and limit it to 5 but it's not working properly

This is my current query, just need to get the last 5 records (probably by the festivalid)

SELECT  f.*, 
    v.total, 
    v.votes, 
    v.festivalid, 
    ifnull(r.reviewcount,0) as count 
FROM festivals f 
INNER 
JOIN vote v 
    ON f.festivalid = v.festivalid 
LEFT OUTER
JOIN (SELECT festivalid, 
             count(*) as reviewcount 
        FROM reviews 
        GROUP BY festivalid) as r 

    ON r.festivalid = v.festivalid  
WHERE f.datefrom > CURRENT_TIMESTAMP            
    ORDER BY f.datefrom, f.eventname

Upvotes: 1

Views: 439

Answers (1)

Salil
Salil

Reputation: 47512

 ORDER BY f.datefrom DESC, f.eventname DESC
 Limit 5

Upvotes: 3

Related Questions