You must Sign In to post a response.
  • Category: SQL Server

    Last record

    I need a query for how to select last record in the table.
  • #581872

    try like this query

    SELECT * FROM dms_document WHERE DocID=(SELECT MAX(DocID) FROM dms_document )

  • #581873
    There must be some ID column or a date column so that you can Order the record like

    Select TOP 1 * from EMP Order by ID DESC


    Select TOP 1 * from EMP Order by RegisDate DESC

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #581880

    Selecting the last record can be done only based on some column.

    You can use Select TOP 1 * from tablename Order by columnname DESC


  • #581881
    Please check the following query:

    SELECT TOP 1 empid FROM TblEmp ORDER BY empid desc;

    Thanks & Regards
    Paritosh Mohapatra
    Microsoft MVP (ASP.Net/IIS)
    DotNetSpider MVM

  • #581937

    SELECT TOP 1 SM_StudentID FROM Studentmaster ORDER BY SM_StudentID

  • #581981

    select TOP 1 * from tablename order by PrimaryKey_Fieldname DESC

    Your Hard work never fails

  • #582401
    try this query

    select max(empid) from tablename

    hope this will help you

  • #585442
    hi friends

    you use following query

    select * from student where rollno=(select max(rollno) from student)

    i use subquery

    the subquery return the maximum rollno value from table

    and in

    outer query return the id from table

    i hope help u

  • #585931
    select top(1) * from city order by id desc
    Chirag - 48
    Enjoy With Errors

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.