SELECT id_member, picture_name, static_name, type,id_picture, seq
FROM member_pic as m1
where id_member=((SELECT TOP 1 id_member
FROM member_pic as m2 where m2.id_member=m1.id_member group by id_member,seq order by seq))
Date :
2015-02-26 17:40:46
By :
Thaidevelopment.NET
No. 5
Guest
Code (SQL)
DECLARE @member_pic TABLE (id_member int, picture_name varchar(100), static_name varchar(100), type varchar(4), seq int)
INSERT INTO @member_pic
VALUES (3,'3a0','3b0','3t0',1),(3,'3a1','3b1','3t0',2),
(3,'3a2','3b2','3t0',3),(2,'2a0','2b0','2t0',1),
(2,'2a1','2b1','2t0',3),(2,'2a2','2b2','2t0',2),
(1,'1a0','2a0','1t0',2),(1,'1a1','1a1','1t0',1)
SELECT xOne.*, yOne.* FROM @member_pic xOne
CROSS APPLY (SELECT TOP 1 * FROM @member_pic yOne WHERE yOne.id_member= xOne.id_member ORDER BY yOne.seq asc) yOne
WHERE xOne.seq = yOne.seq
คุณลองสังเกตุข้อแตกต่างระหว่างคำสั่งเสีย CROSS APPLY VS Sub Query