please can anyone answer this query

Table 1 has 2 columns: EmployeeId,Age
Table 2 has 2 columns: EmployeeId, Region
Write SQL to Find the region who has the oldest person

Answers were Sorted based on User's Feedback



please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns:..

Answer / monal

SELECT REGION,AGE, T1.EMPID FROM T2 INNER JOIN T1
ON T1.EMPID = T2.EMPID WHERE AGE = (SELECT MAX(AGE) FROM T1)

Is This Answer Correct ?    3 Yes 0 No

please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns:..

Answer / shivaraj


select region from table1 where employeeid in (select
employeeid from table2 where age in (select max(age) from
table2))

Is This Answer Correct ?    3 Yes 1 No

please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns:..

Answer / krishna murari chaubey

create table Employee(empId int,age int)
create table Area(empId int,Region varchar(20))

Use Inner Join

select e.empid,e.age,a.region from Employee e inner join
area a on e.empid=a.empid and e.age in
(select max(age) from Employee)

OR


select empid,region from area where empid in
(select empid from Employee where age
in(select max(age) from Employee))

Is This Answer Correct ?    2 Yes 0 No

please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns:..

Answer / monal

SELECT REGION FROM T2 T2 INNER JOIN
T1 T1 ON T1.EMPID = T2.EMPID INNER JOIN
(SELECT MAX(AGE) AGE FROM T1) TBLAGE ON T1.AGE = TBLAGE.AGE

Is This Answer Correct ?    1 Yes 0 No

please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns:..

Answer / anil panwar

select t1.id, t2.region from table t1 left outer Join table2 t2
on t1.id=t2.id
where t1.id in (select id from table1 where age=(select
max(age) from table1))

Is This Answer Correct ?    1 Yes 1 No

please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns:..

Answer / anil panwar

Hi Shivaraj
the ans you have given that is correct but
anyway,
if different employee id have same age and different region
and region is null in that case will not show Null region
for that employee


it may be solution....

select t1.id, t2.region from t1 left outer Join t2
on t1.id=t2.id
where t1.id in (select id from t1 where age=(select max(age)
from t1)) group by t1.id, t2.region

Is This Answer Correct ?    0 Yes 0 No

please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns:..

Answer / devendra sharma

select ID, region from tab1 where ID in
(select ID from tab2 where isnull(age,0)=(select max(age)
from tab2))

Is This Answer Correct ?    0 Yes 0 No

please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns:..

Answer / saravanan p

select e.empid,e2.region from empAge1 e,empAge2 e2
where e.empid=e2.empid and e.age in(select max(age) from
empAge1)

Is This Answer Correct ?    0 Yes 0 No

please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns:..

Answer / gayathri

create table Emp1(EmployeeId int, Age int);
INSERT into Emp1 Values(1,20);
INSERT into Emp1 Values(2,20);
INSERT into Emp1 Values(3,25);
INSERT into Emp1 Values(4,25);
INSERT into Emp1 Values(5,30);
INSERT into Emp1 Values(6,30);
INSERT into Emp1 Values(7,30);

create table Emp_details(EmployeeId int, Region cahr(10));

INSERT into Emp_details Values(1,'del');
INSERT into Emp_details Values(2,'chn');
INSERT into Emp_details Values(3,'mum');
INSERT into Emp_details Values(4,'del');
INSERT into Emp_details Values(5,'cal');
INSERT into Emp_details Values(6,'mum');
INSERT into Emp_details Values(7,'chn');

select Region from Emp_details ed,Emp1 e1
where e1.EmployeeId = ed.EmployeeId
and e1.Age = (select max(Age) from emp1);

Is This Answer Correct ?    0 Yes 0 No

please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns:..

Answer / ramesh babu

Create table #tempempid(Employeeid int,age int)
Create table #tempempregion(Employeeid int,Region varchar
(200))

Insert into #tempempid(Employeeid,age)values(100,25),
(101,35),(103,35),(104,10),(105,12),(106,11),(107,13),
(108,24),(109,22),(110,17),(111,11),(112,25),(113,100) ,
(52,100)
go
Insert into #tempempregion(Employeeid,region)values
(100,'SA'),(102,'SA'),(103,'UK'),(104,'UK'),(105,'PHL'),
(106,'US'),(107,'US'),(108,'US'),(109,'RSA'),(110,'RSA'),
(111,'UK'),(113,'SA'),(52,'CA')

Select T.region,T.Age from
(
Select b.region as Region,a.age as Age,
rank() over(order by age desc) as Rnk
from #tempempid a inner join #tempempregion b on
a.Employeeid=b.Employeeid
)T
Where T.Rnk=1

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

Can we make the the chages By Using the Sql if u know any function or process please inform me Actuall result: BRK1 Break 1 Part 1 00:01:00:00 60 BRK1 Break 1 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 BRK2 Break 2 Part 2 00:01:00:00 60 BRK2 Break 2 Part 3 00:01:00:00 60 BRK3 Break 3 Part 1 00:01:00:00 60 BRK3 Break 3 Part 2 00:01:00:00 60 Desired O/P: BRK1 Break 1 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 Part 3 00:01:00:00 60

0 Answers   Satyam,


What are logical database components? : SQL Server Architecture

0 Answers  


UPDATE statement can on a single table or on the multiple table?

7 Answers   iGate, TCS,


what is Archive old data?

1 Answers  


What is a trace frag? Where do we use it?

0 Answers  






What are the properties of the transaction?

0 Answers  


System variable and temporary variables

0 Answers   Wipro,


when u import an excel file into sql if suppose one column has got a date field with system time attached to it what data type u will use in sql to import it in a table? Note: a condition is the excel file has no primary key defined to a column...also u r importing bulk data into sql

1 Answers  


What samples and sample databases are provided by microsoft?

0 Answers  


What is Cross Join and in which scenario do we use Cross Join?

0 Answers   QuestPond,


What is policy based management (pbm)? : sql server database administration

0 Answers  


what are the types of indexes? : Sql server database administration

0 Answers  


Categories