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

Popular posts from this blog

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Session timeout interceptor in struts 2