0

Hi everybody I need done help with this issue.

Example myDb tabele name people

ID          name        Sex
3   Adam Smith      M
5   Sonia Kolan     F
3   Donald Smith    M

Select id, name from people where name LIKE ‚%Smith%’;

Result

Id   Name 
3   Adam Smith
3   Donald smith

My question is how to transform my result of col name to this view

Id   name  
3    Smith 
3    Smith 

I want too see in col name Expresion from like statement

GMB
  • 216,147
  • 25
  • 84
  • 135
Adrian P.
  • 1
  • 1

2 Answers2

1

I want too see in col name Expresion from like statement

Then just put that literal string in the select clause:

select id, 'Smith' name
from people 
where name like '%Smith%'
GMB
  • 216,147
  • 25
  • 84
  • 135
0

You can join to the table a query that returns only 'Smith':

select p.id, t.name 
from people p
inner join (select 'Smith' name) t
on p.name LIKE concat('%', t.name, '%'); 

See the demo.

Results:
> id | name 
> -: | :----
>  3 | Smith
>  3 | Smith
forpas
  • 160,666
  • 10
  • 38
  • 76