我正在尝试从数据库表中检索最后一条记录。我的问题如下:
Select AppointmentDate from tbAppointment where MID=@MID MID是员工ID代码,主键是id。
由于主键(在我的例子中)是整数,并且在每次插入记录时自动递增,我尝试在主键的基础上获取最后一条记录,因为与其他记录相比,最后一条记录具有最高值的主键。
但是我不能阐明如何给出指定最高值的主键的条件。我需要像下面这样添加主键约束:
Select AppointmentDate from tbAppointment where MID=@MID AND (最高主键值)
发布于 2013-07-01 17:51:38
SELECT TOP 1 AppointmentDate
FROM tbAppointment
WHERE MID = @MID
ORDER BY ID DESC 发布于 2013-07-01 18:08:20
Select Top 1
AppointmentDate from tbAppointment
where MID=@MID
Order By ID Desc这对我很有效,它帮助我检索插入到数据库表中的最后一行。感谢James :)
发布于 2013-07-01 19:13:45
SELECT AppointmentDate
FROM tbAppointment where Mid = (select max(MID) from tbAppointment)https://stackoverflow.com/questions/17401520
复制相似问题