1

Suppose I have a table like:

  id      Model        Color
------  --------     ----------
1        Ford           yellow
2        Ford           green
3        Ford           red
4        Ford           yellow
5        Subaru         yellow
6        Fiat            red

I need to make a query, which returns me every car's color in list, except for fiat car. How to implement this query using firebase query standards?

Maxim Chan
  • 11
  • 1
  • There is not equivalent of a `WHERE NOT` operation in Firebase. You'll either have to exclude the Fiat's client-side or come up with a data structure that allows the server-side filtering (i.e. have a list of colors-of-cars-that-are-not-fiats). – Frank van Puffelen Dec 22 '16 at 14:59
  • 1
    @FrankvanPuffelen am I right in saying [this answer](http://stackoverflow.com/a/26701282/6530134) is related and could help? (it was ironically answered by you!) – Timothy G. Dec 22 '16 at 15:01
  • It's related, but not the same. The one you link is about querying for multiple values, which sometimes is possible. But they're all related in that you'll need to model your data to allow the queries you need for your app. – Frank van Puffelen Dec 22 '16 at 15:02
  • @FrankvanPuffelen Is it a good practice to fetch data from firebase database and save it in the array and then filter accordingly? – Maxim Chan Dec 22 '16 at 15:09
  • It's one common approach. See http://stackoverflow.com/questions/37752402/firebase-database-not-equal-request-alternative-solution-for-ios, http://stackoverflow.com/questions/28582223/is-it-possible-query-data-that-are-not-equal-to-the-specified-condition/28619795#28619795, http://stackoverflow.com/questions/35833790/what-is-the-best-method-to-exclude-data-and-query-parts-of-data-in-a-swift-fireb/35833954#35833954 and probably a few more. – Frank van Puffelen Dec 22 '16 at 16:14
  • @FrankvanPuffelen [http://stackoverflow.com/questions/37752402/firebase-database-not-equal-request-alternative-solution-for-ios](http://stackoverflow.com/questions/37752402/firebase-database-not-equal-request-alternative-solution-for-ios) how to apply this concept in case of android? – Maxim Chan Dec 22 '16 at 17:06
  • The APIs between languages are fairly similar, so I recommend you give it a try ([documentation on list handling](https://firebase.google.com/docs/database/android/lists-of-data)). If you have a specific part where you get stuck, post the code where you got stuck. – Frank van Puffelen Dec 23 '16 at 04:33

0 Answers0