views:

27

answers:

0

I have a query that does some magical sort-group-joining that works just fine on Android 2.2 (froyo) version of SQLite:

SELECT channels.*, p.*
FROM channels 
LEFT JOIN programs p ON channels._id = p.channel_id
JOIN (select p2.channel_id, max(p2.airdate) max_air FROM programs p2 
      GROUP BY p2.channel_id) pj
ON pj.channel_id = p.channel_id AND pj.max_air = p.airdate
ORDER BY channels.channel_index asc;

For some reason, the join doesn't work with Android 2.1 but fails with

no such column: pj.channel_id

I reckon this is because SQLite has been upgraded from 2.1 to 2.2, but what would be the proper SQL that works for both versions?