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;

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("https://examples-sql-queries.firebaseio.com/messages")
    .startAt(startTime)
    .endAt(endTime)
    .once('value', function(snap) {
       console.log('messages in range', snap.val());
    });

Archive from: https://stackoverflow.com/questions/59018170/is-it-possible-to-implement-between-sql-query-in-firebase

Share

You may also like...

Leave a Reply

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