sqlite - SQL: Order by column desc in another table -
i have sql (sqlite database), correctly gets recent message messages table grouped conversation_id message has conversation id other 'none'.
select * messages _id in ( select max(_id) messages conversation_id != 'none' group conversation_id )
however, i'd use "unseenreplies" column in conversation table (which has number count of unseen replies conversation) order messages come out.
i've tried this:
select * messages _id in ( select max(_id) messages m join conversations c on m.conversation_id = c.cid order c.unseenreplies desc m.conversation_id != 'none' group m.conversation_id )
but syntax error near 'where' clause.
just way of explanation 'conversation id' isn't primary key of conversation table, identifier string.
how can fix this? approach join way off?
join
them instead of in
predicate:
select * messages m1 inner join conversations c1 on m1.conversation_id = c1.cid inner join ( select max(_id) maxid messages m m.conversation_id != 'none' group m.conversation_id ) m2 on m1._id = m2.maxid order c.unseenreplies desc
Comments
Post a Comment