Wondering if the FQL has an operator similar to the MySQL
LIKE operator to do string search operations?
FQL does have a similar functionality:
Other functions that are available are
The function we need is the
strpos() function and here how to use it:
SELECT name FROM user WHERE uid IN ( SELECT uid2 FROM friend WHERE uid1=me() ) AND strpos(lower(name),"jo") >=0
The above will match all your friends where the name field contains the letters “jo” (“Joe, John, Joseph…etc”).
Notes to consider:
- To do case-insensitive search, use the
lower()method and make sure that the second parameter (the search value or “jo” in the example above) is also using small letters
- Note the
>=0bit, this is mandatory to get the expected results !
- When a field is used in the
strpos()function, it’s no longer treated as an indexable field!
- Use the
fql.queryTest Console to test your queries
- How To: Create A User Photo Albums Browser Using Facebook Graph API
- How To: Upload A Photo To A User’s Profile Using Facebook Graph API
- How To: Check Status And RSVP To Facebook Events Using Graph API & FQL
- How To: Create Facebook Events Using Graph API – Advanced