mysql - Compare values of two columns -


is there way compare values of 2 columns in mysql? example if have table:

+----------------+ | col1  | col2   | |----------------| | abc   | 123abc | | def   | 234def | |       | 123ghi | +----------------+ 

and wanted retrieve entries in col2 contained values of col1:

+---------+ | newcol  | |---------| | 123abc  | | 234def  |  +---------+ 

how go that?

here pseudo-query explain bit further.

select col2 tablename col2 col1; 

use locate()

where locate(col1, col2); 

it returns non-zero value if col1 contained within col2.

update

note empty substring contained within string, in case need condition:

where length(col1) , locate(col1, col2); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -