Skip to content
Advertisement

How to implement BETWEEN Sql query in Firebase?

I am working on a android Firebase project. I need help in implementing this sql query in Firebase real-time database.

SELECT * FROM table
WHERE price BETWEEN $min AND $max;

Advertisement

Answer

There’s good documentation on how to do firebase queries as well as apply them to ranges.

Something like:

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("table");

Query query = ref.orderByChild("price").startAt(min).endAt(max);

Then you add the appropriate listener for what you are trying to do. (e.g. a ValueEventListener or a ChildEventListener via addValueEventListener or addChildEventListener respectively.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement