Q: Search value in column mysql Im tring to search string in column sql.
I want to search if   (the first 3 caracters of the column =='DOC' and the first word after / is 'FILE1') or the value ends with TMP.
case 
when desc like '%TMP' OR (SUBSTRING(desc, 1, 3) =='DOC') then 'F1'
else 'Not found'
end as 't1'



A: Use the postgresql regex match operator ~ (relevant section of Postgresql 12 docs: here):
select "desc"
     , case 
           when "desc" like '%TMP' OR "desc" ~ '^DOC[^/]*/FILE1/'
           then 'F1'
           else 'Not found'
       end as t1
  from (
           select 'DOCument123/FILE1/' "desc"
        union all
           select 'DOCument123/FILE1/' "desc"
        union all
           select 'DOCument123/FILE1/' "desc"
        union all
           select 'TDZVDLS' "desc"
        union all
           select 'TDZVDLSTMP' "desc"
      ) x;    

Includes 2 syntax corrections:


*

*desc is a reserved sql identifier and needs wrapping in double quotes to be used as a column alias.

*The alis t1 is a column name and is written without the enclosing single quotes.   


A: I think you can do what you want with like:
select (case when col like 'DOC%/FILE1%' then 'F1' else 'Not Found' end)

This is all standard SQL, so it should work on any database.
