sql - Check to see if a column value is contained by another column -


i have table called host in sql follows.

**firstname**   **lastname**  krishna          krishna murthy  jithendra        jithendra reddy  varun            varun kumar  mahendra         varma 

if firstname column part of lastname column need create 1 more column values yes/no. output should follows

**firstname**   **lastname**        **subset**  krishna          krishna murthy      yes  jithendra        jithendra reddy     yes  varun            varun kumar         yes  mahendra         varma               no 

any ideas?

you can use

select firstname, lastname,      case when lastname '%' + firstname + '%'      'yes' else 'no'      end flag host 

to results looking for.

if want search cases forename repeated, might want adjust case lastname firstname + ' %' ensure matches there @ least 2 words, , first in firstname, e.g.

**firstname**   **lastname**        **subset** bob             bobbins             no singlename      singlename          no aaa             bbb aaa             no 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -