开发者

PostgreSQL with Rails, using iLIKE to search a combined two fields?

using PostgreSQL in Rails, I have the the following condition:

['fname || lname || [fname, lname] ILIKE ?', "%#{search}%"]

Search is the user input given to find a user.

I want that to sear开发者_如何转开发ch against fname and lname, that works fine... But if the user searches for james b, looking for james bond, it break, no results are found.

So I want to combine fname with lname (james bond).

I tried brackets, that error'd how do I combine the two in PostgresSQL + rails?


Try this:

Concatenate the two columns as a third column and search from the third column:

   SELECT CONCAT(fname, ' ', lname) as fullname FROM table
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜