I am trying to execute a SQL query in my rails app. The following executes normally since it is looking for an exact match:
connection.query("SELECT *
FROM test
WHERE y=#{connection.quote(name)}
ORDER BY x ASC")
I want to use the LIKE operator to find partial matches. In SQL it would look like:
SELECT * FROM test WHERE y LIKE '%John%' ORDER BY x ASC
How do I do this in my Ruby query? I tried adding %
in a few places but it doesn't work. I get errors that say my query is looking for %'John'%
instead of '%John%'
connection.query("SELECT *
FROM test
WHERE y LIKE #{%connection.quote(name)%}
ORDER BY x ASC")