简体   繁体   中英

search column in other column sql

I have the following query:

SELECT 
    Table1 . *
FROM
    Table1
        inner JOIN
    Table2 ON Table1.Column1 = Table2.Column2

I want to change the query to find NOT only a macth between Table1.Column1 to Table2.Column2 but to find all data where Table1.Column1 is a string inside Table2.Column2 .

What I need to do?

How about something like

SELECT 
    Table1 . *
FROM
    Table1
        inner JOIN
    Table2 ON Table1.Column1 LIKE CONCAT('%',Table2.Column2,'%')

If it's SQL SERVER , use CHARINDEX

SELECT 
Table1 . *
FROM
Table1
    inner JOIN
Table2 ON CHARINDEX(Table1.Column1, Table2.Column2) > 0

Change the ON clause to

SqlServer

ON Table2.Column2 LIKE '%'+Table1.Column1+'%'

MySQL

ON Table2.Column2 LIKE CONCAT('%',Table1.Column1,'%') 

Try this

SELECT 
    Table1.*
FROM
    Table1
        inner JOIN
    Table2 ON T Table2.Column2 Like '%' + Table1.Column1 + '%'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM