日期:2014-05-17 浏览次数:20526 次
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 tba
END
GO
CREATE TABLE tba
(
mId INT,
pId INT,
pFileName VARCHAR(100)
)
INSERT INTO tba
SELECT 20,4,'123.jpg' UNION
SELECT 22,3,'123.jpg' UNION
SELECT 7,6,'Chrysanthemum.jpg' UNION
SELECT 27,4,'clouds.jpg' UNION
SELECT 30,7,'flash.jpg' UNION
SELECT 8,6,'Jellyfish.jpg' UNION
SELECT 5,4,'mamechiyoShare.jpg' UNION
SELECT 17,7,'mamechiyoShare.jpg' UNION
SELECT 9,6,'Penguins.jpg' UNION
SELECT 32,3,'Penguinsaaa.jpg' UNION
SELECT 28,4,'pic_campus.jpg' UNION
SELECT 21,3,'pic_campus.jpg' UNION
SELECT 24,3,'pic_news04.jpg' UNION
SELECT 4,4,'vs2010安装问题.png' UNION
SELECT 29,3,'沙漠.png' UNION
SELECT 31,4,'图片2.jpg' UNION
SELECT 23,3,'图片2.jpg'
select mId,
pId,
pFileName
from tba t
WHERE mId IN (SELECT TOP 1 mId FROM tba WHERE pFileName = t.pFileName)
mId pId pFileName
4 4 vs2010安装问题.png
5 4 mamechiyoShare.jpg
7 6 Chrysanthemum.jpg
8 6 Jellyfish.jpg
9 6 Penguins.jpg
20 4 123.jpg
21 3 pic_campus.jpg
23 3 图片2.jpg
24 3 pic_news04.jpg
27 4 clouds.jpg
29 3 沙漠.png
30 7 flash.jpg
32 3 Penguinsaaa.jpg