Wiaanities Forum  
February 05, 2012, 03:04:58 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Send this topic  |  Print  
Author Topic: Test your database query skill  (Read 1265 times)
ramanathan
Newbie
*
Posts: 1


Email
« on: December 04, 2008, 04:13:47 AM »
Reply with quoteQuote

Hi,

 Below is the table showing some records, you need to create a query which has the output showing the employee name and his related lead name

Table data's

emp_idemp_namelead_id
1Palaniappan1
2moorthy1
3senthil1
4manoj2
5deepa3

the result will be

emp_namelead_name
PalaniappanPalaniappan
moorthyPalaniappan
senthilPalaniappan
manojmoorthy
deepasenthil

Note: it is single table not seperate table

Ramanathan.
Logged
Muthuganesh
Newbie
*
Posts: 9


Email
« Reply #1 on: December 07, 2008, 11:39:58 PM »
Reply with quoteQuote

Hi ramanathan,
                       There may be more than one solution(query) to this problem.I am sure this will be one of the solutions.
                 
select t1.emp_name,t2.emp_nam as lead_name from employee t1,employee t2 where t1.lead_id=t2.emp_id;

TableName:
employee=tablename

Fields

emp_name
emp_id
lead_id

Description:

Its a simple join in same table

t2 and t1 is the alis name of that table,usually we use 2 table in different name here you refer same table.If you did'nt give that where condition it show all combination.

I request you to give me feedback for this solution

M.Muthuganesh
Navagate
Logged
Pages: [1]
  Reply  |  Send this topic  |  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC