Red Devil Red Devil - 19 days ago 6
SQL Question

Join 2 tables with different name using inner join

I have 2 table first is

Before

lotname
--------
R16A
R17A
R17B
R18A
R18B


2nd is

After

lotname
--------
R16AA
R17A
R17B
R18AAA
R18B


I want to join both the table so that everything match like
R16A
should match with
R16AA


if i write this code

select * from before
join after
on before.lotname = after.lotname


O/P

lotname lotname
R17A R17A
R17B R17B
R18B R18B


I want o/p like

Lotname Lotname
----------------------------
R16A R16AA
R17A R17A
R17B R17B
R18A R18AAA
R18B R18B

Answer
SELECT *
FROM before
INNER JOIN after
    ON after.lotname LIKE before.lotname + '%'