如果我们在2个不同的表中有2个相同的列,如何找到值?

时间:2017-11-16 10:13:16

标签: sql sql-server linq

正如你在照片上看到的那样。我有2张桌子(A和B)。 KlantId 在2个表格中很常见。我想要实现的是,如果我提供电子邮件,那么我可以获得 reservatieNummer enter image description here

2 个答案:

答案 0 :(得分:1)

select b.reservatieID 
from tablea as a
inner join tableb as b on a.KlantId = b.KlantId 
where a.email="whatever"

并在where条件

中指定电子邮件

答案 1 :(得分:0)

使用linq:

var ReservatieID =  tableA.Join(tableB, ta =>ta.KlantId, tb =>tb.KlantId, (ta,tb) =>new{tableA = ta, tableB = tb})
                    .Where(a=> a.email == "whatever@domain.com").Select(a=> new{a.reservatieID});