SQL英国邮编匹配查询

SQL UK postcode matching query

我有两张表,一张有部分英国邮政编码,一张有完整的英国邮政编码。 我需要 return 完整邮政编码中与部分邮政编码匹配的那些行。请您就代码提出建议,因为我自己很困惑。

下面是表格示例:

    Table1

    Postcode
    AB10 1


    Table2

    Postcode    Title FName  SName
    AB10 1NN    Ms    Davina Gabriel
    AB11 5BY    Mr    James  Mclean
    AB11 5DL    Mrs   Janet  Maccallum
    AB11 5DP    Mr    Mick   Milne
    AB11 5DY    Mr    Trevor Mcwhinnie
    AB10 1GJ    Mrs   Ruth   Smith

在上面的例子中,我只是在寻找 Davina Gabriel 女士和 Ruth Smith returned。

怎么样...

SELECT *
FROM Table2
INNER JOIN Table1 ON (Table2.Postcode LIKE CONCAT(Table1.Postcode, '%'))

试试这个...

select a.* from table2 a, table1 b where a.postalcode like b.postalcode + '%'