select tb.id,tb.title from (
select id,title from table1
union
select id,title from table2
) td
已经创建了视图,但是必须有一个唯一ID才好分页
怎么为上面创建唯一ID以便下面分页
分页查询代码
string sql = string.Format("select top {0} * from td where title like '%{2}%' and id not in (select top {1} id from td where title like '%{2}%' order by id desc) order by id desc", pageinfo.pagerecode, (pageinfo.pagecount - 1) * pageinfo.pagerecode, serachtxt);
------解决方案--------------------
- SQL code
select no=row_number() over(order by getdate()) from ...
------解决方案--------------------
SQL2000?2005?
2005:
- SQL code
select *from(select tb.id,tb.title,px = row_number() over(order by getdate())from (select id,title from table1union select id,title from table2) td)tewhere px between 1 and 10
------解决方案--------------------
2005或是2008用row_number即可。
------解决方案--------------------
select row_number() over(order by id) tb.id,tb.title from (
select id,title from table1
union
select id,title from table2
) td
------解决方案--------------------
- SQL code
select row_number() over(order by id) tb.id,tb.title from (select id,title from table1union select id,title from table2) td
------解决方案--------------------
2000用identity