wat will be the sql query to extract only last 3 records
from table supose table hving thousands for records
Answers were Sorted based on User's Feedback
Answer / shubhra
This query will give last three record in the table in the
same order.
CREATE TABLE dbo.Test1 (
[ID] [int] ,
[FirstName] [varchar](25),
[LastName] [varchar](25)
) ON [PRIMARY]
INSERT INTO Test1 VALUES(1, 'Bob','Smith')
INSERT INTO Test1 VALUES(2, 'Dave','Jones')
INSERT INTO Test1 VALUES(3, 'Karen','White')
INSERT INTO Test1 VALUES(1, 'Bob','Smith')
INSERT INTO Test1 VALUES(4, 'Bobby','Smita')
select identity(int,1,1) as SlNo,* into #temp from Test1
select * from (select top 3 * from #temp order by slno
desc) a order by slno
drop table #temp
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / nitesh srivastava
select * from emp
minus
select * from emp where rownum<(select count(*)-2 from emp)
| Is This Answer Correct ? | 8 Yes | 10 No |
hi this is tulasi ravi
id - ravi106109@gmail.com
select empno,sal from emp where rowid in
(select rowid from emp
minus
select rowid from emp where rownum<=(
select count(*)-3 from emp))
feel free to mail queries,,,.....
| Is This Answer Correct ? | 3 Yes | 5 No |
Answer / kumar
very good kumar
a sweet and simple query
i tink u can go to microsoft for work
wat a query it is
good keep it up
| Is This Answer Correct ? | 1 Yes | 3 No |
Answer / bobby
select * from table_name where <Primary key Column-
name> != all
(select top (@@rowcount-3) <Primary key Column-name> from
Table_name)
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / pawan k. dubey
1-select * from employee where emp_id >(select count(*)-3
from employee)
2-select * from employee where emp_id in
(
select top 3 emp_id from employee order by emp_id DESC
)
| Is This Answer Correct ? | 2 Yes | 6 No |
Answer / arun kumar k s
drop table #temp select identity(int,1,1) as SlNo, * into
#temp from TABLE_NAME select top 3 * from #temp order by
SlNo desc
arun_4454@yahoo.co.in
| Is This Answer Correct ? | 0 Yes | 4 No |
Detail about query optimizer?
You want to check the syntax of a complicated update sql statement without executing it. What command should you use?
Explain an automatic checkpoint
What is 2nf normalization?
What is page-level compression?
What is self contained scalar sub query?
what is difference between having and where clause ?
what is isolation level at dead lock?
in tabase table having a column in it empname field is there which having 5 duplicate values is there i want deleted all the duplicates i want showing only one name only.
What are the advantages dts has over bcp?
What are the ways available in sql server to execute sql statements?
How to enter unicode character string literals in ms sql server?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)