GeekInterview.com
Answered Questions

How to eliminate duplicate rows from a table leaving one from the duplicates?

Asked By: Interview Candidate | Asked On: Aug 10th, 2005

Answered by: Dhiraj on: Aug 29th, 2011

select distinct * from table_name

Answered by: shiiva on: Feb 4th, 2011

Delete the Records selected from the below query:

select a.*
from emp1 a, emp1 b
where a.empno = b.empno
and a.rowid < b.rowid 

shiv

Maxvalue.SQL select the nth highest value from a table

Asked By: Interview Candidate | Asked On: Sep 10th, 2005

Select level, max('col_name') from my_table where level = '&n' connect by prior ('col_name') >'col_name')group by level;example:given a table called emp with the following columns:-- id number-- name varchar2(20)-- sal number---- for the second highest salary:-- select level, max(sal) from emp--...

Answered by: nklpunitha on: Feb 20th, 2010

Try the below query, it will give the correct output
Select * from emp where salary = (select min(salary) from (select distinct salary from emp order by salary desc) where rownum < n)

Answered by: Avashisth on: Feb 20th, 2010

-- To get nth Highest
select
distinct salary

from (select salary,dense_rank() over(order by salary desc) as sal from Table )where

sal = &n

--To get nth Lowest

select distinct salary

from (select salary,dense_rank() over(order by salary) as sal from Table )

where sal = &n

Find out nth highest salary from emp table

Asked By: Interview Candidate | Asked On: Aug 29th, 2004

Select distinct (a.Sal) from emp a where &n = (select count (distinct (b.Sal)) from emp b where a.Sal < = b.Sal);for eg:-enter value for n: 2sal---------3700

Answered by: bhavikgore on: Oct 27th, 2012

This will work for only highest salary n=1 but not work for 2nd and rest nth salary...
Did you have tried this?

Answered by: rohitosu on: Jul 30th, 2012

Code
  1.  SELECT * FROM  (SELECT employee_id, salary, dense_rank() OVER ( ORDER BY salary DESC)  r
  2.   FROM employees) a
  3.   WHERE a.r =3 ;

Can a primary key contain more than one columns ?

Asked By: Interview Candidate | Asked On: Aug 26th, 2005

Answered by: Mark Haynes on: Sep 23rd, 2011

Yes, a primary key can contain more than one one column. Per EF Cobb's definition, a primary key is the sole candidate key on a relation variable (table) formed from one or more attribute values (c...

Answered by: venky on: Sep 22nd, 2011

in some situations...
if the selected primary key column contains unique row elements..
need only one column....
if it contains any duplicates...then we take two columns

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us: