1

I am using SlashDB for a REST API (SQL Pass-thru) for MySQL.

This allows you to write a SQL query where your parameters (to be replaced by user text) are preceeded by :. For example:

select * from mydb where name = :name;

would work fine, assuming that -- if name represents a value that might be changed to "Atlanta" -- that what you want is:

select * from mydb where name = 'Atlanta';

The problem is that I am trying to use like with wildcards at the beginning and end of the parameter. The query I want to run is:

select * from mydb where name like '%Atlanta%';

but when I input

select * from mydb where name like '%:name%';

the result is:

select * from mydb where name like '%'Atlanta'%';

which of course does not work.

Victor Olex
  • 1,458
  • 1
  • 13
  • 28
Hack-R
  • 22,422
  • 14
  • 75
  • 131

1 Answers1

1

Good question. It can be a little tricky but here's how you can accomplish this:

SELECT *
FROM mydb
WHERE name LIKE CONCAT('%', :name, '%')

P.S. Please tag your SlashDB questions with tag: slashdb

Victor Olex
  • 1,458
  • 1
  • 13
  • 28