[英]How to find MySQL records having one field's content within any row of another field
The problem is simple. 问题很简单。 Is there a MySQL query allowing, in a single table, to find all records having some content within any row of another column ?
是否存在一个MySQL查询,该查询允许在单个表中查找另一列的任何行中具有某些内容的所有记录?
In other words, I have a table with 2 columns : "FirstName" and "LastName". 换句话说,我有一个包含2列的表:“名字”和“姓氏”。
My automatic filler has melted some of them. 我的自动填充器融化了其中一些。
So I would like to find all occurences of "LastName"s that also appear in column "FirstName". 因此,我想找到所有出现在“ FirstName”列中的“ LastName”。
That way, all the Doe JOHN would be detected, because "John" must 100% be in the list of "FirstName"s, whereas John DOE would not be detected, because there is nearly no chance to find DOE as a first name... 这样,将检测到所有Doe JOHN,因为“ John”必须100%位于“ FirstName”列表中,而不会检测到John DOE,因为几乎没有机会将DOE作为名字。 ..
Just perform a self join over the table. 只需在桌子上进行自我联接即可。 It should look something like this:
它看起来应该像这样:
SELECT
*
FROM
CUSTOMER C1
INNER JOIN
CUSTOMER C2 ON (C1.FirstName = C2.LastName OR C1.LastName = C2.FirstName);
I'm guessing you want something like: 我猜你想要这样的东西:
SELECT *
FROM nametable
WHERE firstname IN (select lastname FROM nametable)
That will find row where the first name exists as a last name in the table. 这将在表中找到名字作为姓氏存在的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.