开发者

SQLite select query with like condition in reverse

I'm trying to write a query in php that will select a row from a database t开发者_StackOverflowhat partially matches a string.

Better explained via an example:

Say my DB has a field called numberString, with value 'abcd'. I want to write a query that, given "123abcd", will return a field of that row of the database.

SELECT mood 
  FROM USERS 
 WHERE numberString like '%$giveNumberString'"

$giveNumberString is the functions parameter (i.e. the string that I want to look for)

But I think those two numberString and '%$givenNumberString'" should be like the other way around in order for the query to work as expected. Is there a way to do this?


Ok the table looks like this:

id | username | numberString | mood
-------------------------------------
1  | myUsrNam | abcd         | happy

Now I want, given "123abcd", to retrieve the mood of that person. In other words to match 123abcd against abcd.


I'm not sure this is a legal syntax, but let me try a wild guess: have you tried

SELECT mood from users where '$giveNumberString' like '%' || numberString || '%'

?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜