是否可以有一个优化的单个查询语句来返回不同的行数?见下文:
create table #tbl (id int, name varchar(30))
go
INSERT INTO #tbl (id, name) values(1, 'test1')
INSERT INTO #tbl (id, name) values(2, 'test2')
INSERT INTO #tbl (id, name) values(1, 'test3')
INSERT INTO #tbl (id, name) values(1, 'test4')
INSERT INTO #tbl (id, name) values(3, 'test5')
INSERT INTO #tbl (id, name) values(1, 'test6')
INSERT INTO #tbl (id, name) values(1, 'test7')
INSERT INTO #tbl (id, name) values(2, 'test8')
INSERT INTO #tbl (id, name) values(1, 'test9')
我想在下面返回一条记录:
id name
--- ----
3 test1
3 test2
3 test3
3 test4
3 test5
3 test6
3 test7
3 test8
3 test9