PayPal Interview Question






Comment hidden because of low score. Click to expand.
2
of 2 vote

SELECT fistname, lastname
FROM employee
limit 3,1

gives 4th row, if you want 8th row then replace 3 by 7

- kaustubh deshmukh September 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

-- solution #1: nested top

SELECT TOP 1 FName
FROM
(
SELECT TOP 10 FName
FROM Names
ORDER BY FName
) sub
ORDER BY FName DESC

-- solution #2: NOT IN

SELECT TOP 1 FName
FROM Names WHERE FName NOT IN
(
SELECT TOP 9 FName
FROM Names
ORDER BY FName
)
ORDER BY FName

-- solution #3: derived count
-- this assumes FName is unique

SELECT FName
FROM Names
WHERE
(
SELECT COUNT(*)
FROM Names n2
WHERE n2.FName <= Names.FName
) = 10

-- solution #4: MAX

SELECT FName = MAX(FName) FROM
(
SELECT TOP 10 FName
FROM Names
ORDER BY FName
) sub

- Anonymous November 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Select * from(select salary from emp order by salary)where ROWNUM=x;

- Anonymous December 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This sql command wont work as rownum will never be equal to x

- Anonymous August 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

stackoverflow.com/questions/16568/how-to-select-the-nth-row-in-a-sql-database-table

- Haga July 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select * from table limit n-1,1

- karthik August 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select * from table limit n-1,1

- karthik August 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

(select * from (select rownum as rnum, First_name||' '||Last_name as name from employees) where rnum=31)

here you are actually creating a table in the sub query in which the rownumber is adding up as rnum and in the main query you are selecting that rnum value to what ever the n value is ..

This question is actually asked to test your abilities in writing sub queries....

- Sai Phaneendra August 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select * from (select rownum r,tablename.* from tablename) where r=n;

n is required row number

- ranajit kumar behera November 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it is the best answer according to above interview question

it is running well in oracle

but it shows some error when i am trying to use it in my .net application

- ranjit kumar behera November 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Below query will give nth row.

SELECT* FROM (SELECT ROW_NUMBER() OVER(ORDER BY CUSTOMERKEY) AS ROWNUMBER, DIMCUSTOMER.* FROM DIMCUSTOMER)A WHERE A.ROWNUMBER=5

- Sidhartha July 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select col1,col2 from (select col1,col2,rowid from table_name where rownum<=n order by rowid desc)where rownum=1

- emailns11 August 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT * FROM table1 limit 7 offset 6;

- shajitha October 30, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT * FROM Customers LIMIT 2,1;

displays 3rd row of table named Customers

- anonymous May 26, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I think u can use ROWID concept to fetch the nth row!!

- navanee November 28, 2010 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More