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是否为空;

posted @ 2011-07-22 18:09  _best  阅读(249)  评论(0)    收藏  举报