在我加入相同的表两次后,如何在WHERE子句中调用具有相同列名的值?

时间:2013-10-06 16:41:12

标签: mysql sql

我将从一个例子开始:

*Table1*
ID
PhoneNumber1
PhoneNumber2

*Table2*
PhoneNumber
SomeOtherField

SELECT *
FROM Table1 t1
INNER JOIN Table2 t2
   ON t2.PhoneNumber = t1.PhoneNumber1
INNER JOIN Table2 t3
   ON t3.PhoneNumber = t1.PhoneNumber2
-- here is the question how do I call same column which have same name?
-- I want to do a where clause like below:
WHERE SomeOtherField(from first Table2) = SomeOtherField(from second Table2)

示例来自以下问题,但我们提出了不同的问题: What's the best way to join on the same table twice?

1 个答案:

答案 0 :(得分:1)

WHERE t2.SomeOtherField = t1.SomeOtherField