Union关键字的用法
SELECT
ProductName,
[UserInfo].UserName,
[ReviewContent]
,[ReviewDateTime]
,[ReviewLevel]
,[IsShowd]
,[IPAddress]
FROM [B2CRelease].[dbo].[ProductReviewsInfo],[B2CRelease].[dbo].[UserInfo],[B2CRelease].[dbo].[Products]
where [ProductReviewsInfo].UserId=[UserInfo].Id and [ProductReviewsInfo].ProductId=[Products].Id
union
select
ProductName,[UserName],[ReviewContent]
,[ReviewDateTime]
,[ReviewLevel]
,[IsShowd]
, null from [ProductReviewsInfo],[Products] where [Products].Id=[ProductReviewsInfo].ProductId and UserId is null
当第二张表的列不足时可用Null来填充表结构,userid is Null 是判断userid是否为空;

浙公网安备 33010602011771号