0

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;
Hanzla
  • 214
  • 5
  • 15
  • Might want to look at this https://stackoverflow.com/questions/42228445/query-firebase-database-with-two-between-conditions – Kryesec Nov 24 '19 at 13:41

2 Answers2

1

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());
    });
robsiemb
  • 6,157
  • 7
  • 32
  • 46
1

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.

robsiemb
  • 6,157
  • 7
  • 32
  • 46