Search code examples
sqlmariadbmariasql

Using ? in sql create '' around parameter


I try to create a query like such:

SELECT * FROM table_name WHERE column_name LIKE %?%

The error:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%'word'%' at line 1

How to avoid the two apostrophes?

This works:

SELECT * FROM table_name WHERE column_name LIKE ?

but then I would need an exact match.


Solution

  • I suspect that you want:

    WHERE column_name LIKE CONCAT('%', ?, '%')
    

    However, I would suggest that you append the wildcards in the app and simply use:

    WHERE column_name LIKE ?