Pardeep Pardeep - 1 year ago 52
MySQL Question

search in a column having entries like `a%` as entry for a column

I want a query to return rows with the column having entries like following:

abcda%aaa, pa%rdeep, sonisa%b etc.

Tried using following but doesn't get the desired results.

select * from table where column like "%a%%"

I want correct replacement for above so as to search for only those rows having
as an entry for the column in the table not those starting with a.

Answer Source
create table j1
(   id int auto_increment primary key,
    thing varchar(100) not null

insert j1(thing) values ('abcda%aaa'),('fish'),('pa%rdeep'),('cat'),('sonisa%b'),('a'),('a\\%');

select * from j1 where thing like '%a\%%';
| id | thing     |
|  1 | abcda%aaa |
|  3 | pa%rdeep  |
|  5 | sonisa%b  |

Please see MySQL String Literals