You are on page 1of 6

If you want to load empty table then you use the fastload so it will very usefull than the

mutiload..because fastload performs the loading of the data in 2phase..and it noneed a work table for loading the data.. so it is faster as well as it follows the below steps to load the data in the table Phase1-It moves all the records to all the AMP first without any hashing Phase2-After giving endloading command Amp will hashes the record and send it to the appropriate AMPS . Multiload: It does the loading in the 5 phases Phase1:It will get the import file and checks the script Phase2:It reads the record from the base table and store in the work table Phase3:In this Application phase it locks the table header Phase4:In the DML opreation will done in the tables Phase 5: In this table locks will be released and work tables will be dropped.
To fine nth highest salary SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT b.sal) FROM EMP B WHERE a.sal<=b.Sal); Enter value for n: 2 2nd highest salary

SELECT SALARY FROM EMPLOYEE WHERE SALARY (SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY <> (SELECT MAX(SALARY) FROM EMPLOYEE))

select max(salary ) from emp table where sal<(select max


(salary)from emp table) Latest date (oracle) SEL * FROM svuedwtg19_e.orgproductdaycostcomponent WHERE (day_dt, org_id) IN (SEL MAX(day_dt), org_id FROM orgproductdaycostcomponent GROUP BY org_id) Latest date (teradata)

SEL * QUALIFY ROW_NUMBER() OVER (PARTITION BY org_id ORDER BY day_dt DESC )= 1 FROM orgproductdaycostcomponent

For email id sel SUBSTRING('biswajit.pal@avivaindia.com',1, index('biswajit.pal@avivaindia.com','@')-1 ) substr('TEST@COMPANY.COM',instr('TEST@COMPANY.COM','@')+1)

To Delete Duplicate in oracle


DELETE FROM our_table WHERE rowid not in (SELECT MIN(rowid) FROM our_table GROUP BY column1, column2, column3... ;

To Delete Duplicate in Teradata 1. create a set table and dump the record itll only take Unique record 2. Create table and do the primary index on the column which should not contain duplicate

1.

Re: Difference between group by clause and having clause Group By: select ename,sum(sal) from emp group by ename; Group by clause is used to group the functions.In the above example by using ename column the functions are all grouped. To get the individual column result group by clause is used.Otherwise individual column result is not possible. Having: Group functions cannot be used in where.To restrict row by group function having clause is used. For Example: select ename,sum(sal) from emp where sum(sal)>1000 group by ename; The above query throw error like this.

ERROR at line 1: ORA-00934: group function is not allowed here The following query will fetch result according to the condition specified in having clause: select ename,sum(sal) from emp group by ename having sum(sal)>1000; The above query limits the number of rows. 1. The GROUP BY clause will gather all of the rows together that contain data in the specified column(s) and will allow aggregate functions to be performed on the one or more columns Aggregate fns are like SUM,COUNT,MIN,MAX and AVG The syntax for the GROUP BY clause is: SELECT column1, column2, ... column_n, aggregate_function (expression) FROM tables WHERE predicates GROUP BY column1, column2, ... column_n; The HAVING clause is used in combination with the GROUP BY clause. It can be used in a SELECT statement to filter the records that a GROUP BY returns The syntax for the HAVING clause is: SELECT column1, column2, ... column_n, aggregate_function (expression) FROM tables WHERE predicates GROUP BY column1, column2, ... column_n HAVING condition1 ... condition_n; 2. Re: Difference between group by clause and having clause

In normal select statement WHERE caluse is used to limit the query results, whereas HAVING caluse is used to limit the query results when GROUP BY caluse is used.

Q:

What is the difference between GROUP BY and HAVING clauses? The GROUP BY and HAVING clauses are used together. The HAVING clause is used as a

Bryan Oliver says:

final filter (rather than as a conditional filter) on the aggregate column values in the result set of a SELECT statement. In other words, the query has to be grouped before the HAVING clause can be applied. For example, consider the following statement, which displays the count of students in various classes (classes of students = 1, 2, 3, 4, corresponding to freshman, sophomore, and so on).

TOP N rows from a table (oracle)


SELECT DISTINCT FROM ( SELECT sal_rank FROM WHERE sal_rank store_id store_id, DENSE_RANK() OVER (ORDER BY store_id DESC) storeaswas_OL ) <= 10;

Rank and Dense rank Function in Oracle


In Oracle/PLSQL, the rank function returns the rank of a value in a group of values. It is very similar to the dense_rank function. However, the rank function can cause non-consecutive rankings if the tested values are the same. Whereas, the dense_rank function will always result in consecutive rankings. The rank function can be used two ways - as an Aggregate function or as an Analytic function.

Syntax #1 - Used as an Aggregate Function


As an Aggregate function, the rank returns the rank of a row within a group of rows. The syntax for the rank function when used as an Aggregate function is: rank( expression1, ... expression_n ) WITHIN GROUP ( ORDER BY expression1, ... expression_n ) expression1 .. expression_n can be one or more expressions which identify a unique row in the group.

Note: There must be the same number of expressions in the first expression list as there is in the ORDER BY clause. The expression lists match by position so the data types must be compatible between the expressions in the first expression list as in the ORDER BY clause.

Applies To:

Oracle 9i, Oracle 10g, Oracle 11g

For example: select rank(1000, 500) WITHIN GROUP (ORDER BY salary, bonus) from employees; The SQL statement above would return the rank of an employee with a salary of $1,000 and a bonus of $500 from within the employees table.

Syntax #2 - Used as an Analytic Function


As an Analytic function, the rank returns the rank of each row of a query with respective to the other rows. The syntax for the rank function when used as an Analytic function is: rank() OVER ( [ query_partition_clause] ORDER BY clause )

Applies To:

Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g

For example: select employee_name, salary, rank() OVER (PARTITION BY department ORDER BY salary) from employees where department = 'Marketing'; The SQL statement above would return all employees who work in the Marketing department and then calculate a rank for each unique salary in the Marketing department. If two employees had the same salary, the rank function would return the same rank for both employees. However, this will cause a gap in the ranks (ie: non-consecutive ranks). This is quite different from the dense_rank function which generates consecutive rankings.

In Oracle/PLSQL, the dense_rank function returns the rank of a row in a group of rows. It is very similar to the rank function. However, the rank function can cause non-consecutive rankings if the tested values are the same. Whereas, the dense_rank function will always result in consecutive rankings. The dense_rank function can be used two ways - as an Aggregate function or as an Analytic function.

Syntax #1 - Used as an Aggregate Function


As an Aggregate function, the dense_rank returns the dense rank of a row within a group of rows. The syntax for the dense_rank function when used as an Aggregate function is: dense_rank( expression1, ... expression_n ) WITHIN GROUP ( ORDER BY expression1, ... expression_n ) expression1 .. expression_n can be one or more expressions which identify a unique row in the group.

Note: There must be the same number of expressions in the first expression list as there is in the ORDER BY clause.

The expression lists match by position so the data types must be compatible between the expressions in the first expression list as in the ORDER BY clause.

Applies To:

Oracle 9i, Oracle 10g, Oracle 11g

For example: select dense_rank(1000, 500) WITHIN GROUP (ORDER BY salary, bonus) from employees; The SQL statement above would return the dense rank of an employee with a salary of $1,000 and a bonus of $500 from within the employees table.

Syntax #2 - Used as an Analytic Function


As an Analytic function, the dense_rank returns the rank of each row of a query with respective to the other rows. The syntax for the dense_rank function when used as an Analytic function is: dense_rank() OVER ( [ query_partition_clause] ORDER BY clause )

Applies To:

Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g

For example: select employee_name, salary, dense_rank() OVER (PARTITION BY department ORDER BY salary) from employees where department = 'Marketing'; The SQL statement above would return all employees who work in the Marketing department and then calculate a rank for each unique salary in the Marketing department. If two employees had the same salary, the dense_rank function would return the same rank for both employees.

You might also like