从两个不同的表中选择记录 [英] Select records from two different table
本文介绍了从两个不同的表中选择记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友,
我使用两张桌子(A和B)。
A表有TempId,Email,PhoneNo,userid字段
B表有Userid,名称字段
现在我想从Table获取所有记录A,然后使用表A用户ID我想从表B中获取名称。
我想要Linq查询。
任何提示都将不胜感激。
问候,
RK
解决方案
在这里使用连接左连接或右连接
选择 A.Email ,A.TempId,A.PhoneNo,B.Name 来自 A 内部 加入 B A.userid = B.userid
< pre lang =sql> SELECT * FROM A
INNER JOIN B on A.TempId = B.UserId
我认为几乎所有人都听到错误,因为它提到它是sql query.So让我们看看它是如何在linq中完成的。
http://www.dotnet-tricks.com/Tutorial/linq/UXPF181012 -SQL-Joins-with-C [ ^ ]
如何使用linq查询连接两个表 [ ^ ]
http://stackoverflow.com/questions/611074/linq-joining-two-tab les [ ^ ]
http:// social .msdn.microsoft.com /论坛/ zh-CN / csharpgeneral / thread / 370d7296-5289-430a-a26a-50614fde187a [ ^ ]
Hi Friends,
I am using two tables(A and B).
A Table has TempId,Email,PhoneNo,userid fields
B Table has Userid,Name fields
Now I want to fetch all records from Table A, then with Table A userid I want to fetch the name from the Table B.
I want Linq query for this.
Any tips will be appreciated.
Regards,
RK
解决方案
use joins here either left join or right join
select A.Email,A.TempId,A.PhoneNo,B.Name from A Inner Join B on A.userid=B.userid
SELECT * FROM A INNER JOIN B on A.TempId = B.UserId
I think almost all hear mistakes here as mentioning it as sql query.So lets see how it is done in linq from these..
http://www.dotnet-tricks.com/Tutorial/linq/UXPF181012-SQL-Joins-with-C[^]
how to join two tables using linq query[^]
http://stackoverflow.com/questions/611074/linq-joining-two-tables[^]
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/370d7296-5289-430a-a26a-50614fde187a[^]
这篇关于从两个不同的表中选择记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文