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.

WHERE price BETWEEN $min AND $max;

2 Answers

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.

You can use the following method

new Firebase("")
    .once('value', function(snap) {
       console.log('messages in range', snap.val());

Archive from:


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *