且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在2个表中选择具有不同连接条件的一列

更新时间:2022-12-12 10:54:18

您需要两次加入文件表。因此,您需要为表分配两个不同的别名,以便在引用它时没有歧义。

You need to join to the file table twice. For that reason you need to assign the table two different aliases so there is no ambiguity when referencing it.
select
	category.id,
	bannerfile.[path] as bannerimagepath,
	thumbfile.[path] as thumbimagepath
from 
	[category]
	left join [file] as bannerfile on category.bannerid = bannerfile.id
	left join [file] as thumbfile on category.thumbid = thumbfile.id


您可以使用以下查询



You can use following query

Select id,(Select path from file where A.bigimageid =id ) as bannerPath,
(Select path from file where A.thumbimageid =id ) as ThumbPath FROM Bannerimages A


假设如果bannerid或thumbid中的某个地方的横幅图像表包含空值



那么将如何编写查询



你能告诉我如何处理连接中的null
Suppose if banner image table if somewhere in bannerid or thumbid contain null value

then how will write query

Can you tell me how to deal with null in join