code=HTML]
id TypeName SecondID Image
1 联想 1 1.jpg
2 宏基 1 2.jpg
3 联想 2 3.jpg
4 宏基 2 4.jpg
5 华硕 1 5.jpg
6 联想 3 6.jpg
7 华硕 3 7.jpg
8 宏基 3 8.jpg
[/code]
按照TypeName 查询不重复的数据 如红字显示select pt.* from ProductType pt
where TypeName=(select top 1 * from ProductType where id=pt.id)报错:
消息 116,级别 16,状态 1,第 1 行
当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式。
id TypeName SecondID Image
1 联想 1 1.jpg
2 宏基 1 2.jpg
3 联想 2 3.jpg
4 宏基 2 4.jpg
5 华硕 1 5.jpg
6 联想 3 6.jpg
7 华硕 3 7.jpg
8 宏基 3 8.jpg
[/code]
按照TypeName 查询不重复的数据 如红字显示select pt.* from ProductType pt
where TypeName=(select top 1 * from ProductType where id=pt.id)报错:
消息 116,级别 16,状态 1,第 1 行
当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式。
go
insert into tb
select
1, '联想' ,1, '1.jpg' union all
select
2 ,'宏基', 1, '2.jpg' union all
select
3 ,'联想', 2, '3.jpg' union all
select
4 ,'宏基', 2, '4.jpg' union all
select
5 ,'华硕', 1, '5.jpg' union all
select
6 ,'联想', 3, '6.jpg' union all
select
7 ,'华硕', 3, '7.jpg' union all
select
8 ,'宏基', 3, '8.jpg' select * from tb where tb.secondid=1
drop table tb
go(8 行受影响)
id TypeName SecondID Image
----------- ---------- ----------- --------------------
1 联想 1 1.jpg
2 宏基 1 2.jpg
5 华硕 1 5.jpg (3 行受影响)