一段ASP查询语句

来源:百度知道 编辑:UC知道 时间:2024/05/12 08:11:19
例如:表1有sid cid sname(sid为自动编号)
表2有 nid sid nname
表1中的sid和表2中的sid 数据相同

现在要实现的是显示表2中的最新10条记录。
并且 表2中的sid=表1中的sid
并且表1中的 cid=1
条件的意思就是: select top 10 xxxxxxxxxx where 表2.sid=表1.sid and 表1.cid=1

想了半天没想出来怎么做。该怎么写才对啊

自动生成的序号是不能这样使用的,因为是自动增加的,等于记录的条数(初始),但删除时是不能自动补充的,由于我们无法控制而绝非是大数据库中的外部或内部关键字的!

你能保证每一个都是相同的吗?数据少了可以使用,只是一种试验性!这个字段的目的是保证最新记录的提取。

如select * from XX order by Sid DESC

所生成的视图或表,是按加入记录的先后顺序而生成的!

你这里又同时作为两个表中的外部或内部关键字,所以这句话就应该如你所想:

select top 10 * from 表1,表2 where 表1.sid=表2.sid order by sid DESC

但在以后的处理数据中,不要使用这样的方法了!

关键字的定义必须要好控制才行!

应该这样改就可以
select top 10 xxxxxxxxxx from 表1,表2 where 表2.sid=表1.sid and 表1.cid=1
xxxxxxxxxx 的写法必须申明数据所在表
例如:表2.nname,表1.sname,....

select top 10 xxxxxxxxxx where 表2.sid=表1.sid and 表1.cid=1
Order By 表2.NID DESC
select top 10 xxxxxxxxxx where 表2.sid=表1.sid and 表1.cid=1