name LIKE whereclause

I want to retrieve users whose name property is similar to a search text (i.e. a user searching for other users by name).

 let whereClause = "name LIKE '\(name)'"

Here’s all of my code for the query
The problem is it only gives me an object when the text matches the name exactly. I would like it to return results even if there is a partial match of the text.

For example it would be great if I could retrieve all users whose name contains any of the text that I am searching for (rather than only users whose names match the search text exactly).

the LIKE operator uses pattern matching. The value you’re matching against should have the % character. For example,

name LIKE ‘foobar%’

will match:

foobar1
foobar12
foobar123
foobarABC

Does it help?

Mark

Adding the % character solved it. Thanks!

Is there also a clause to retrieve objects that contain that string? Not just as the prefix.

For example, if I searched “Doe”, I would want “John Doe” to come back as a result.

But with name LIKE, if I searched “Doe”, then I wouldn’t get “John Doe”. Because my search text would have to match all beginning characters.

%Doe

Awesome. Is there a name for this method of searching / whereClause formatting? Or is this exclusive to Backendless. Thanks

It is the standard SQL like operator:
http://www.w3schools.com/sql/sql_like.asp

Sorry to bring up such an old topic.

I am trying to use the WHERE name LIKE ‘%’ and this is bringing back weird results.

where data LIKE ‘f%’

brings back the data “crap”

my understanding is that shouldn’t return anything at all.

I am trying to figure out how to set up my where scheme to return words that contain or start with my search term. However, I am not being able to filter my results with POStman

this setup works when encoded

where%20data%20LIKE ‘%cr returns ‘crap’
where%20data%20LIKE '%rc does not return ‘crap’

this is weird
where%20data%20LIKE ‘%ff%’ returns ‘crap’

I wouldn’t want crap to show up If all i typed was ‘ff’ in a query

Hi Jared,

Out of curiosity, why do you put data into quotes?

Regards,
Mark

You can see examples of using LIKE in a where clause in the following section of the documentation:

I do not know exactly what transformations postman does with parameters when it comes to encoding. Personally, I find our own REST Console which is built into Backendless Console more convenient when composing a Backendless API request. You can find REST Console when you navigate to the Data section, select a table and then click the REST Console tab.

Hey @mark-piller

I realize the error that I was making this morning. In my like clause I was including double quotes around the query item. Instead, what worked was were single quote

data LiKE ‘%cr’

Instead of

data LIKE “%cr”

And to answer your question. That was my first MySQL query I’ve constructed. Now I know better!

Hi Jared,

I am glad you figured it out. Please make sure to check with the docs, they include multiple examples.

Regards,
Mark

1 Like

Thank you. Is there a note in the docs to specifically use single quotes? I’m sorry, I must’ve missed that. I was going off the docs but missed that specification.

Anyway, all is working now when Url encoding and using single quotes. Thank you!

Hi Jared,

there is no such note (although there are a lot of examples of using SQL queries on our docs and you can see the syntax there).
This is the standard syntax of SQL queries.

Best regards,
Stanislaw

Thanks for the feedback and support AND tolerating my newbie questions.

Much appreciated.

You’re welcome!