how to select 5 to 7 rows from a table, which contains 10 rows?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
Answer / kaviraj.y
SELECT * from emp_table WHERE e_id>=5 AND e_id<=7;
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / narayana
select * from emp order by empid
offset 4 rows
fetch next 3 rows only
| Is This Answer Correct ? | 1 Yes | 0 No |
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 |
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 |
Answer / pravnch
Select EmpNo, EName,Sal from EmpTable where EmpNo between 5
and 7
| Is This Answer Correct ? | 0 Yes | 0 No |
How to create a user name in a database?
What are the new features in sql server 2016?
What is the size of transaction log file?
What is index, cluster index and nonclustered index?
What objects does the fn_my_permissions function reports on? : sql server security
What is merge?
i have table students with fields classname,studname select * from students classname studname 1 xxxxx 1 yyyy 1 zzzz 2 qqqq 2 tttt 3 dsds 3 www i want the output should be No of students in class 1 : 3 No of students in class 2 : 2 No of students in class 3 : 2
Can anyone explain difference between Database, Data warehouse and Data mart with some example?````
What is table-valued sub query?
Can a database be shrunk with users active?
Which table keeps the locking information?
What do you understand by coalesce in 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)