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
Post a Comment