0

I query my room database using an IN query with a list like this

@Query("SELECT * FROM card WHERE cardId IN (:cardIds)")
LiveData<List<Card>> getCardsByIds(List<Integer> cardIds);

But it's then removing duplicates and is returning them in order of the primary key Id's, this is not what I want. I want it to return like the list I gave it in the order it was given to the database, so for instance given a list of <1,3,2,1,4,5,1,2> I want the same back, but right now I'm getting back <1,2,3,4,5> I've looked at getting the data directly from the cursor which seems ridiculous as android insists you don't do this, and I've tried using raw query which I cant seem to get to play nice with my live data, any ideas out there? seems like it should be super straight forward as sqlite does this out the box, is it that room is applying DISTINCT and ORDER BY primary key when returning the data, and if it is does anyone know of a way to change this?

EDIT this clearly asks more than the original question and it may be an sqlite issue rather than an android room issue meaning the tags are more relevant here

martinseal1987
  • 1,862
  • 8
  • 44
  • 77
  • Possible duplicate of [Room not returning duplicates](https://stackoverflow.com/questions/56099187/room-not-returning-duplicates) – Abhimanyu May 12 '19 at 17:31
  • think youll find ive added to the original which warranted its own question and i may have just found this to be an sqlite issue rather than an android rrom issue – martinseal1987 May 12 '19 at 17:37

0 Answers0