Like operator in inner join in SQL
A bit of an odd data model aside, you've turned the tables around in the LIKE
part (table1.name should be a part of table2.name, not the other way around), and you need to add the percents to the value, not the name of the field, that means not quoting the name;
SELECT table1.*, table2.z
FROM table1
INNER JOIN table2
ON table2.name LIKE CONCAT('%', table1.name, '%')
AND table1.year = table2.year
An SQLfiddle to test with.
Use a LIKE clause in part of an INNER JOIN
Your first query will work but will require a full table scan because any index on that column will be ignored. You will also have to do some dynamic SQL to generate all your LIKE clauses.
Try a full text search if your using SQL Server or check out one of the Lucene implementations. Joel talked about his success with it recently.
Inner join with like operator?
MS-Access uses *
where you have %
https://support.office.com/en-gb/article/like-operator-b2f7ef03-9085-4ffb-9829-eef18358e931
(One of many reasons I hate MS-Access, it's too proprietary)
Like operator in SQL Inner Join
I think you are compare # too... try to replace it:
Select
t1.Handle ,
t1.Name ,
t1.Description
from
table1 t1 inner join table2 t2
on t2.Handle = t1.Handle
inner join table3 t3
on t2.Handle like CONCAT('%',REPLACE( t3.CurrentHandle,'#',''), '%')
Hope this help!
Inner join with like clause
you have to form the clause using concat ...
...LIKE CONCAT('%',tbl_albums.name, '%');
there is no +
operator like this in mysql
Related Topics
Trim Left Characters in SQL Server
Exec Stored Procedure into Dynamic Temp Table
T-SQL - Group by with Like - Is This Possible
Building SQL Strings in Access/Vba
Insert Multiple Rows in SQLite
SQL Query for Finding Rows with Special Characters Only
Generate_Series in Postgres from Start and End Date in a Table
Split a Varchar in Db2 to Retrieve a Value Inside
SQL Server - Does [Select] Lock [Update]
Is There a Coalesce-Like Function in Excel
How to Format Bigint Field into a Date in Postgresql
Psql: Server Closed the Connection Unexepectedly
SQL Join on Nearest Less Than Date
Need SQL Query to Find Parent Records Without Child Records
How to Connect to SQL Express "Error: 26-Error Locating Server/Instance Specified)
A How to Escape %% When Building Like Queries in Rails 3/Activerecord