Back to top"/>Facebook FQL: How To Search Partial Strings (Similar To MySQL Like Operator) | MasteringAPI

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 now(), strlen(), substr() and strpos().

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 >=0 bit, 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.query Test Console to test your queries
Back to top
Tagged with:
 
  • http://onitsukatiger.lah.cc/ Lynn

    Perfect advice! I have already been seeking something similar to this for a long time now. Cheers!

  • http://www.facebook.com/people/Daniel-Sailes/100001900043206 Daniel Sailes

    haha, thankyou mate. this website has worked wonders for me the past few daws :D

  • None

    Where is this documented?