Friday, April 27, 2007

Some Classic SQL's:

SQL to get Second Max form a column:

select * from EMPLOYEE where SALARY = (
select
max(SALARY)
from
EMPLOYEE
where
SALARY < (select max(SALARY) from EMPLOYEE)

--In the condition we are trying to select max from a list which would contain values less than max(salary) and it works =)

-------------------------------------------------------------------------------------

FINDING DUPLICATE ROWS IN A TABLE

-------------------------------------------------------------------------------------

select FAC_OID, count(*) from v_XYX_TABLE group by FAC_OID HAVING count(*) > 1;

will retrieve all values of fac_oid from the table where the fac_oid is repeating. :)



-------------------------------------------------------------------------------------
DELETE AND RENAME A COLUMN FROM ORACLE TABLE

-------------------------------------------------------------------------------------


alter table srgt_path_prelim_lgd drop column PRELIM_LGD_PCT

alter table srgt_path_prelim_lgd rename COLUMN PRELIM_LGD_PCT TO PRELIM_LGD_PCT1

-Sunny

No comments: