Common SQL Queries converted for the Firebase Database - The Firebase Database For SQL Developers #4

Firebase · 164K views · 2016 · 12:21

Open on YouTube

Databases & storageWeb developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering how to run multi-field, LIKE-style or compound queries in Firebase, since it shows the data-structuring workarounds for a database that can only order by one property.

Recommended by 11 people across 10 different months, 2016 to 2023.

What it is

A 12-minute Firebase team video, part 4 of the 'Firebase Database for SQL Developers' series, that translates eight common SQL queries into Firebase Realtime Database queries. It covers ordering, filtering, prefix search with startAt/endAt, and combining fields into composite keys.

What people said

Recommends Frank van Puffelen · 2016-11 · Stack Overflow · on “AngularFire2 - Firebase how to filter a query?”

The Firebase Database can only order by/filter on a single property. You may be able to combine the two values into a single property to accomplish your use-case. See [LINK] I also recommend checking out this video, which covers the same approach: [this video]

Recommends John O'Reilly · 2016-12 · Stack Overflow · on “Android firebase apply multiple queries”

Unfortunately this isn't straightforward using Firebase.....there's good example of doing something very similar in following video by Firebase guys (about 9 mins in) [this video]

Recommends JoKr · 2016-12 · Stack Overflow · on “How to apply multiple query in android firebase?”

Take a look at this video (it's in JavaScript, but it exactly solves your problem): [this video] Basically, you need to structure your data for your queries. In OP example Question will have field like category_level: "cat_1" . Then you can perform query equalTo("cat_1") . You can leave out both category and level fields if you need it for other queries (but you will need to handle duplication in that case). If you know that your number of items is small, simplest solution is to just pull all category=cat and filter level=1 items.

Recommends Salmin Skenderovic · 2017-01 · Stack Overflow · on “How to query Firebase database object when criteria property is nested?”

I think there are several good examples on these two videos. I think the second video answers your question, but watch both since they are very easy to follow: #1: [this video] and #2: [LINK]

Recommends Philip Sawyer · 2017-05 · Stack Overflow · on “Firebase query to fetch specific users by their user IDs in iOS swift”

Yes Firebase does support this type of query. You have to use the orderByChild() method on the database reference. This Firebase Youtube video goes through how to do this. Common SQL Queries converted for the Firebase Database - The Firebase Database For SQL Developers #4 [this video]

Recommends Mohamed Hesham · 2017-06 · Stack Overflow · on “Firebase query does not allow order on multiple properties?”

queryOrderedByChild can be used only once. a workaround would be |_objectiId1 | |_ userId:1 | |_ timestamp:143242344 | |_ userId_timestamp:1_143242344 |_objectiId2 |_ userId:1 |_ timestamp:143243222 |_ userId_timestamp:1_143243222 Then try : FIRDatabaseQuery *query = [[firebase queryOrderedByChild:@"userId_timestamp"] queryEqualToValue:@"1_143242344"]; check this out [this video] another way to do it would be : |_objectiId1 |_ userId1: | |_ objectId11:143242344 | |_ objectId12:143243222 |_ userId2: Then querying path is [LINK] and then order by value

Recommends Alex Mamo · 2017-06 · Stack Overflow · on “How do I Query this in Android Studio using Firebase?”

Please take a look at this video [this video] . Hope you understand better how to query using to values. Is the same example as explained by me above.

Recommends Emeka Obianom · 2017-07 · Stack Overflow · on “How to correctly query list in firebase/angularfire?”

For your first question. Before you use the EqualTo filter there should first be an OrderBy filter... This OrderBy filter tells the query which field should EqualTo refer to... So your query should look like this. let path = this.API_EVENTS_PATH; return db.list(path , { query: { orderByChild: 'from', equalTo: 'sharikov.vladislav@gmail.com', } }); For your second question How to filter items by 2 fields In Nosql database like firebase you are normally allowed to filter by only 1 field. Every other manipulations are done considering on how you organise your database. Check out this firebase video [this video] which shows you how to do your normal SQL queries on firebase database. Enjoy

Recommends Ziya ERKOC · 2017-07 · Stack Overflow · on “Firebase query multiple keys Android client”

Current Firebase Database API does not provide exact way for combining queries. However, in the video [this video] person from Firebase tells how to structure your database to relieve the burden. I suggest, instead of seperating leftEyeHeight and leftEyeWidth you can merge them up by simply leftEyeSize whose value could be written as (leftEyeHeight, leftEyeWidth) This will halve your problem even if you write each query manualy

Recommends cutiko · 2017-07 · Stack Overflow · on “Firebase Query Chaining?”

You dont need to nest the creator inside the game, instead displayName and uid should be direct childs of the game. Then you still have the problem because you want 2 search criteria. Sadly you cant do that in Firebase, yet. But what you can do is to generate another node inside the game called "state_uid". And then, query like child("games").orderByChild("state_uid").equalsTo("1_"+uid); Look at this Firebase video [this video]