tags:

views:

53

answers:

1

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
+2  A: 
 ORDER BY f.datefrom DESC, f.eventname DESC
 Limit 5
Salil
I tried that but a record could be added where the datefrom is less than others already stored.I think i need to grab the last 5 ids that are put in no matter what the datefrom is
AdRock
Actually you were right and all i did was change the order by to festivalid DESC LIMIT 5 and it worked
AdRock