[英]SQL UK postcode matching query
I have two tables, one with partial UK postcodes and one with full UK postcodes. 我有两张桌子,一张桌子有部分英国邮政编码,一张有完整的英国邮政编码。 I need to return those rows within the full postcodes which match the partial postcodes. 我需要在完整的邮政编码中返回与部分邮政编码匹配的那些行。 Please can you advise on the code to do this as I am confusing myself. 请让我对代码提出建议,以免使我感到困惑。
Here's an example of the tables: 这是表格的示例:
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
In the above example I am just looking for Ms Davina Gabriel and Ruth Smith to be returned. 在上面的示例中,我只是想找回Davina Gabriel女士和Ruth Smith。
How about... 怎么样...
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 + '%'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.