Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


how to select 5 to 7 rows from a table, which contains 10 rows?

Answers were Sorted based on User's Feedback



how to select 5 to 7 rows from a table, which contains 10 rows?..

Answer / soorai ganesh

Should Implement ROW_NUMBER() method.

Just take this Example.

Create table emp(empid int, ename varchar(50),salary numeric
(9,2)

Insert into emp values(1,'Employee1',10000)
Insert into emp values(2,'Employee2',20000)
.
.
Insert into emp values(10,'Employee10',100000)

Consider the above table which have 10 records. Now u
want to select 5,6,7 Rows in this table. Just try this
query.

SELECT E.EmpID,E.EName,E.Salary FROM
(
SELECT ROW_NUMBER() OVER(ORDER BY EmpID ASC) AS Rno, *
FROM emp
) E
WHERE E.Rno >= 5 and E.Rno <= 7

Thats all.
If anyone have other such good idea kindly share........

Is This Answer Correct ?    27 Yes 3 No

how to select 5 to 7 rows from a table, which contains 10 rows?..

Answer / ayyappanramachandran

You can achieve this by using following Query

select * from(select top 3 * from employees where
employeeid in(select top 7 employeeid from employees where
employeeid not in(select top 4 employeeid from employees
order by employeeid)))e order by employeeid.

Thanks
AyyappanRamachandran

Is This Answer Correct ?    13 Yes 2 No

how to select 5 to 7 rows from a table, which contains 10 rows?..

Answer / smitha

select * from (select row_number() over (order by empid) as
row, *
from employee)a
where a.row between 4 and 5

Is This Answer Correct ?    7 Yes 3 No

how to select 5 to 7 rows from a table, which contains 10 rows?..

Answer / s. ramesh

select * from ( select rownum r, comp_name from metatest )
where r > 4 and r < 8;

Is This Answer Correct ?    3 Yes 2 No

how to select 5 to 7 rows from a table, which contains 10 rows?..

Answer / priyanka

select top 3 * from emp where id not in
(select top 4 id from emp order by id)

Is This Answer Correct ?    2 Yes 1 No

how to select 5 to 7 rows from a table, which contains 10 rows?..

Answer / kaviraj.y

SELECT * from emp_table WHERE e_id>=5 AND e_id<=7;

Is This Answer Correct ?    1 Yes 0 No

how to select 5 to 7 rows from a table, which contains 10 rows?..

Answer / narayana

select * from emp order by empid
offset 4 rows
fetch next 3 rows only

Is This Answer Correct ?    1 Yes 0 No

how to select 5 to 7 rows from a table, which contains 10 rows?..

Answer / sajida

select rnum, d.* from dept d, (select rownum rnum , deptno
from dept ) e
where d.deptno = e.deptno and rnum between 5 and 7;

Is This Answer Correct ?    2 Yes 2 No

how to select 5 to 7 rows from a table, which contains 10 rows?..

Answer / tb

select a.empid, a.ename,a.salary from (select * from emp
order by empid desc LIMIT 6) b INNER JOIN (select * from
emp order by empid asc LIMIT 7) a on b.empid=a.empid

Is This Answer Correct ?    1 Yes 1 No

how to select 5 to 7 rows from a table, which contains 10 rows?..

Answer / pravnch

Select EmpNo, EName,Sal from EmpTable where EmpNo between 5
and 7

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

Write a sql query to sort on different column name according to the parameters passed in the function?

0 Answers  


What is policy based management (pbm)? : sql server database administration

0 Answers  


Can we install sql server 2016 on windows 7?

0 Answers  


What is multilevel indexing?

0 Answers  


What is a full text index?

0 Answers  


Table - Products has number of products as below Productid ProductName 1 iPhone 2 iPad 3 BlackBerry Table - SalesPersonProduct has the below records Salespersonid productid S1 1 S1 2 S1 3 S2 1 S3 2 Write a SQL query that returns the number of sales for each product

2 Answers  


You have developed an application which uses many stored procedures and triggers to update various tables users ocassionally get locking problems which tool is best suited to help you diagnose the problem?

0 Answers  


What is a unique index?

0 Answers  


What is the difference between HAVING clause and the WHERE clause?

7 Answers  


What is difference between views and stored procedures?

0 Answers  


How can you start sql server in different modes?

0 Answers  


What is a db view?

0 Answers  


Categories