Compare two columns in mysql

Many database queries rely on seeing if two columns match / differ, however sometimes you may want to check if either column contains a sub-string of the other. MySql allows you to do this, but it isn’t that well documented, so hopefully this will help someone looking for this in the future

SELECT * FROM table WHERE col1 LIKE CONCAT(‘%’, col2, ‘%’) OR col2 LIKE CONCAT(‘%’,col1,‘%’)


Tags: developmentproblemdevelopersolutiontip