首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

专拣看看这个SQL语句如何实现

2012-01-15 
专拣看看这个SQL语句怎么实现原来是这样实现的:SelectLClassCodeFrom表1Where表1.ProductCode表2.Product

专拣看看这个SQL语句怎么实现
原来是这样实现的:
Select   LClassCode   From   表1     Where   表1.ProductCode=表2.ProductCode  
但是现在   表1   中的内容分在两个表(表1、表3)中,但两个表结构相同,
想用Uinon把两个表关联起来,可是有错误
(Select   LClassCode   From   表1
union   Select   LClassCode   From   表3)   a
  Where   a.ProductCode=表2.ProductCode  
请问应该怎么实现

[解决办法]
Select LClassCode From 表1 Where 表1.ProductCode=表2.ProductCode

这样写可以??
如果可以的话
select LClassCode From
(Select LClassCode From 表1
union Select LClassCode From 表3) a
Where a.ProductCode=表2.ProductCode

[解决办法]
select a.LClassCode From
(Select LClassCode From 表1 union Select LClassCode From 表3) a, 表2 b
Where a.ProductCode=b.ProductCode
[解决办法]
select a.LClassCode From
(Select * From 表1 union Select * From 表3) a, 表2 b
Where a.ProductCode=b.ProductCode

热点排行
Bad Request.