高手请进~~~~求一条SQL
怎样查询出g_Tb1,g_Tb2,g_Tb3三个表的前三条记录
g_Tb1
-----------------
tb1ID tb1Name
2 aa
3 bb
5 cc
6 dd
g_Tb2
-----------------
tb2ID tb2Name
33 aa
44 bb
55 cc
67 dd
tb3ID tb3Name
2 aa
34 bb
56 cc
67 dd
需要结果:
-------------------------------------------------
tb1ID tb1Name tb2ID tb2Name tb3ID tb3Name
2 aa 33 aa 2 aa
3 bb 44 bb 34 bb
5 cc 55 cc 56 cc
[解决办法]
select top 3 tb1ID,tb1Name,tb2ID,tb2Name,tb3ID,tb3Name
from
(select id = (select count(1) from g_tb1 where tb1id <= a.tb1id),* from g_tb1 a)t1,
(select id = (select count(1) from g_tb2 where tb2id <= b.tb2id),* from g_tb2 b)t2,
(select id = (select count(1) from g_tb3 where tb3id <= c.tb3id),* from g_tb3 c)t3
where t1.id = t2.id and t1.id = t3.id