27,579
社区成员
发帖
与我相关
我的任务
分享
--select * from dbo.ProductTable where ProductCode in(
select ProductCode from dbo.CustomerProductTable where customercode=@ClientNo
--)
返回结果(其中有两条重复)
ProductCode
--------------------------------
15
13
13
select * from dbo.ProductTable where ProductCode in(
select ProductCode from dbo.CustomerProductTable where customercode=@ClientNo
)
用户名 用户号
---------------------
张飞 155
刘备 169
产品名 产品编号
---------------------
青龙刀 40
赤兔马 41
方天戟 42
青罡剑 43
用户号 产品编号
---------------------
155 40
155 40
155 41
155 42
169 42
169 43
-------------
青龙刀 40
赤兔马 41
方天戟 42
青龙刀 40
青龙刀 40
赤兔马 41
方天戟 42
alter table [用户产品表] add AutoID int identity(1,1) not null
alter table ztable add xID int identity(1,1) not null
declare @tb1 table([用户号] int,[产品编号] int)
insert @tb1
select 155,40 union all
select 155,40 union all
select 155,41 union all
select 155,42 union all
select 169,42 union all
select 169,43
declare @tb2 table([产品名] varchar(6),[产品编号] int)
insert @tb2
select '青龙刀',40 union all
select '赤兔马',41 union all
select '方天戟',42 union all
select '青罡剑',43
declare @tb3 table([用户名] varchar(4),[用户号] int)
insert @tb3
select '张飞',155 union all
select '刘备',169
SELECT A.[用户号], B.[产品编号]
FROM @tb1 A FULL JOIN @tb2 B ON A.[产品编号] = B.[产品编号]
WHERE A.[用户号] = '155'
用户号 产品编号
----------- -----------
155 40
155 40
155 41
155 42
select a.* from 产品表 a,用户产品表 b
where a.产品编号=b.产品编号 and b.用户号=@ClientNo