Sql语句,怎样让pFileName只出现一次
表加入如下所示
mId pId pFileName
20|4|123.jpg
22|3|123.jpg
7|6|Chrysanthemum.jpg
27|4|clouds.jpg
30|7|flash.jpg
8|6|Jellyfish.jpg
5|4|mamechiyoShare.jpg
17|7|mamechiyoShare.jpg
9|6|Penguins.jpg
32|3|Penguinsaaa.jpg
28|4|pic_campus.jpg
21|3|pic_campus.jpg
24|3|pic_news04.jpg
4|4|vs2010安装问题.png
29|3|沙漠.png
31|4|图片2.jpg
23|3|图片2.jpg
[解决办法]
select * from tb t where mid=(select min(mid) from tb where pFileName=t.pFileName)
[解决办法]
IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'tba')BEGIN DROP TABLE tbaENDGOCREATE TABLE tba( mId INT, pId INT, pFileName VARCHAR(100) ) INSERT INTO tbaSELECT 20,4,'123.jpg' UNIONSELECT 22,3,'123.jpg' UNIONSELECT 7,6,'Chrysanthemum.jpg' UNIONSELECT 27,4,'clouds.jpg' UNIONSELECT 30,7,'flash.jpg' UNIONSELECT 8,6,'Jellyfish.jpg' UNIONSELECT 5,4,'mamechiyoShare.jpg' UNIONSELECT 17,7,'mamechiyoShare.jpg' UNIONSELECT 9,6,'Penguins.jpg' UNIONSELECT 32,3,'Penguinsaaa.jpg' UNIONSELECT 28,4,'pic_campus.jpg' UNIONSELECT 21,3,'pic_campus.jpg' UNIONSELECT 24,3,'pic_news04.jpg' UNIONSELECT 4,4,'vs2010安装问题.png' UNIONSELECT 29,3,'沙漠.png' UNIONSELECT 31,4,'图片2.jpg' UNIONSELECT 23,3,'图片2.jpg' select mId, pId, pFileNamefrom tba tWHERE mId IN (SELECT TOP 1 mId FROM tba WHERE pFileName = t.pFileName)mId pId pFileName4 4 vs2010安装问题.png5 4 mamechiyoShare.jpg7 6 Chrysanthemum.jpg8 6 Jellyfish.jpg9 6 Penguins.jpg20 4 123.jpg21 3 pic_campus.jpg23 3 图片2.jpg24 3 pic_news04.jpg27 4 clouds.jpg29 3 沙漠.png30 7 flash.jpg32 3 Penguinsaaa.jpg