Search code examples
mysqlsqlsql-like

SQL Select pattern like column_name


Are there such things as a sql query whereby the results are limited with being contained in the query value.

Normally like is :

SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;

I would like it to be

SELECT column_name(s)
FROM table_name
WHERE pattern LIKE column_name;

For example:

id   |   val
1    |   c:/tests/one
2    |   c:/tests/two
3    |   c:/

I can query using 'c:/tests/two/fail/results', and be returned 2 and 3, as they are sub strings.


Solution

  • SELECT column_name
    FROM table_name 
    WHERE instr('c:/tests/two/fail/results', column_name) > 0;