Interview Questions  

Go Back   Interview Questions > Interview Questions & Answers > Information Technology > Databases > SQL

SQL SQL Interview Questions, Learn by sharing SQL Interview Questions asked in various Companies, Get Career advices, Interview Procedures from SQL experts, Post asked SQL Interview Questions and Answers.

   

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-19-2008, 03:14 PM
Senior Member
 
Join Date: Feb 2008
Posts: 1,046
Default What will be the sql query to extract only last 3 records from




What will be the sql query to extract only last 3 records from table suppose table having thousands of records ?
Reply With Quote
  #2 (permalink)  
Old 06-26-2008, 10:08 AM
Junior Member
 
Join Date: Jun 2008
Posts: 1
Default Answer Of Asked Question

JUST BASED ON YOUR ID FIELD WRITE QUERY LIKE THIS YOU WILL GET ONLY LAST THREE RECORDS FROM THOUSANDS OF RECORDS.
SUPPOSE U HAVE A TABLE EMPLOYEE WITH FIELDS EMP_ID ,EMP_NAME,EMP_AGE,EMP_DESG,EMP_SAL ETC..............

HAVING EMP_ID INT DATA-TYPE,
FOR GETTING ONLY LAST THREE RECORDS JUST U HAVE TO WRITE QUERY LIKE THIS,


SELECT TOP 3 * FROM EMPLOYEE ORDER BY EMP_ID DESC

OR IF U DON'T HAVE FIELD LIKE MY SUGGESTED TABLE U CAN JUST REPLACE THE FIELD NAME EMP_ID WITH YOUR FIELD HAVING SERAIL NO OR LIKE THAT WHICH HAVE INT , NUMERIC OR DECIMAL DATA-TYPE

Reply With Quote
Reply

Tags
database questions, servers questions, sql interview questions

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On