0

The SQL query that I want to apply is:

SELECT time FROM Appointment WHERE date = "3/15/2019" AND time = "9:00AM"

but I don't know how to translate it in Firebase. I am using Firebase in Android Studio. My goal here is to prevent date and time duplicate since the app that I'm developing is an online appointment.

Database:

Appointment
    angelcrist
        aptype: "Objective(Computerized)"
        date: "3/15/2019"
        name: "Hephep Horray"
        time: "9:00AM"
    miriammejia
        aptype: "Objective(Computerized)"
        date: "3/5/2019"
        name: "Romz Ysmael"
        time: "9:00AM"
BSMP
  • 4,596
  • 8
  • 33
  • 44
  • Possible duplicate of [Query based on multiple where clauses in Firebase](https://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase) – André Kool Mar 08 '19 at 17:11

2 Answers2

2

There is no way you can do this with the Firebase realtime database. It does not have the capability to perform filtering on multiple conditions. If you have a SQL background, I can say that there are no "multiple where clauses" in Firebase. If you want to check for matches on multiple properties, you'll have to create a composite field as explained in my answer from the following post:

If you consider at some point to try using Cloud Firestore, please note it allows you to filter on multiple conditions. Chaning multiple whereTo calls are working perfectly fine.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
0

First fetch your Appointment data for that particular date using below query, and loop through dataSnapshot childrens to check if you have the time available for that date.

reference.orderByChild('date').equalTo("<yourDate>")
.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(DataSnapshot snap: dataSnapshot.getChildren()) {
               //Check for time here
            }
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
});
ManishPrajapati
  • 459
  • 1
  • 5
  • 16