I want to display all the worker names whose city="Varanasi" and gender="Male" and salary is between 5000 to 15000 in a Recycler View. In this case the name of the shown worker must be displayed. What query must be applied and how should it be achieved?
            Asked
            
        
        
            Active
            
        
            Viewed 5,309 times
        
    2
            
            
        - 
                    1Possible duplicate of [Query based on multiple where clauses in firebase](http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase) – Bob Snyder May 17 '17 at 21:54
 
2 Answers
2
            First, I think you need save the salary with double value, not string.
You need your reference at worker node, then add a listener and iterate the values. Also you need a worker class to obtain the data.
yourReference.orderByChild("city").equalTo("Varanasi").addListenerForSingleValueEvent(){
    @Override
    public void onDataChange(Datasnapshot data){
       for(Datasnapshot d: data.getChildren()){
         yourClass work = d.getValue(yourClass.class);
         if(work.getGender().equals("Male"){
            double salary = work.getSalary();
           if(salary  > 5000 && salary < 15000){
                 //save the worker into a list. 
            }
         } 
       }
      }
    }
}
        danflzz
        
- 44
 - 2
 
- 
                    1Is it a safe approach to fetch all the data but to show only relevant ones? – Surya Teja Karra Aug 27 '17 at 04:12
 
1
            
            
        Acording to this tutorial, The Firebase Database For SQL Developers you can create a new field for each node named: city_gender. For you particular example the value of this field will be Varanasi_Male. This how it should look like:
city_gender: "Varanasi_Male"
In this way, you can query your Firebase database for every worker who is a male and works in Varanasi. In the same way you can achieve this for intervals.
Hope it helps.
        Alex Mamo
        
- 130,605
 - 17
 - 163
 - 193
 
- 
                    Just watched some of the videos from the series, and that looked like a total hack! As of now, do you know if functions were added to allow multi-filtering without having to manually modify the noSQL logic? – Red M Aug 19 '20 at 04:06
 - 
                    @RedM I'm not sure I understand your question, but please post a new one using its own [MCVE](https://stackoverflow.com/help/mcve), so I and other Firebase developers can help you. – Alex Mamo Aug 19 '20 at 08:10
 
