Getting Started with Adobe After Effects - Part 6: Motion Blur
Ask
Ask questions, discuss or help others by answering
Related Posts · View All
SQL Server 141
TSQL 75
SSRS 70
SSIS 66
XML 54

Top Categories · View All
SQL Server 141
TSQL 75
SSRS 70
SSIS 66
XML 54

Find SQL last row without using INDEX and IDENTITY COLUMN and TIME STAMP COLUMN

Aug 1 2010 12:00AM by Pawan   

Hello,

--You can get LAST ROW without using INDEX or IDENTITY COLUMN or TIMESTAMP COLUMN
--- FIND OUT LAST INSERTED ROW WITHOUT USING INDEX / IDENTITY COLUMN / TIME STAMP COLUMN 

--Create a table
CREATE TABLE TestLastQuery (
    Name    VARCHAR (50),
    Address VARCHAR (70)
);

--Insert the values
INSERT  INTO TestLastQuery (Name, Address)
VALUES                    ('Pawan', 'Pune ');

INSERT  INTO TestLastQuery (Name, Address)
VALUES                    ('Gauri', 'A Nagar ');

INSERT  INTO TestLastQuery (Name, Address)
VALUES                    ('Saurabh', 'A Nagar ');

INSERT  INTO TestLastQuery (Name, Address)
VALUES                    ('Himanshu', 'Padmavati ');

INSERT  INTO TestLastQuery (Name, Address)
VALUES                    ('Rahul W', ' Jordan');

-- Use the below query to find out the last inserted row
SELECT   TOP 1 Name,
               Address,
               row_number() OVER ( ORDER BY (SELECT 2)) AS ROWNUMBER
FROM     TestLastQuery
ORDER BY ROWNUMBER DESC;

Submitted under: Microsoft SQL Server · TSQL ·  ·  · 


Pawan
1554 · 0% · 12

1 Replies

  • Pawan,

    There is no guarantee that order by constant clause will return the rows always in same order. Although you can get correctly for small number of rows, you will not get it when there are many number of rows... . If the table don't have clustered index, rows will stored in random order and also if there is no order by clause in query, there is no guarantee for order of rows.

    commented on May 2 2011 10:09AM
    Ramireddy
    2 · 41% · 12972

Your Reply


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]