Timesgroup interview questions: Self JOIN with an example

A self-join is used when a table is joined (compared) to itself.  It means when you need to compare values in a column with other values in the same column in the same table. 
Use of self-joins:  obtaining running counts and running totals in an SQL query.

 Example: select emp1.name,emp1.salary,emp1.state   from employee emp1,employee emp2
  where emp1.state=emp2.state;


  ---------------------------------------------------
  Name                     Salary          State
  ---------------------------------------------------
  Rajesh Singh           10250            Delhi
  Kavita                     10850                Delhi
  Kamal Singh           15250            Delhi
  Rajesh Singh           20250            Haryana
  Manish Kumar        15100            Haryana
  ---------------------------------------------------

Comments

Popular posts from this blog

Read Images from a xlsx file using Apache POI

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

How to create mail message in FRC822 format