João Cunha
João Cunha

Reputation: 10307

Table Query for id and other attribute LIKE

I'm making this query:

User.where("id = ? AND nome LIKE ?",id,nome)

and it returns nil when it should return a value.

If UI do the query for the id alone it works and for the name alone it works.

Can I do this another way? Or am I just way way off?

Upvotes: 1

Views: 316

Answers (2)

Carlos Morales
Carlos Morales

Reputation: 1149

Here is another query:

User.find_by_sql(["select * from users where id = ? AND nome LIKE ?"],id,"%#{nome}%" ")

Upvotes: 0

RAJ
RAJ

Reputation: 9747

You need to add wildcard character % around the nome.

Try like this:

User.where("id = ? AND nome LIKE ?", id, "%#{nome}%")

Upvotes: 3

Related Questions