How to fetch records from employee_master where dept_no = 20 or 50 and employees are active?

 Posted by vishalneeraj-24503 on 12/8/2013 | Category: Sql Server Interview questions | Views: 4769 | Points: 40
Answer:

select * from employee_master 

where (dept_no = 20 or dept_no = 50)
and status = 'ÁA';


Suppose,employee_master contains following column and rows:-

Id      Name    Address   Dept_No    Status


1 Vishal Pune 10 AA

2 Neeraj NULL 20 DD

3 Nitin Nagpur 30 AA

4 Rajesh Jodhpur 20 AA

5 Pooja Nagpur 50 AA

6 Praveen Bhilai 20 AA

7 Vinod NULL 50 DD


Here,Status ='AA' means active employee and 'DD' means De-active employees.

And if i fire above query,then i will get below output as:-

Id      Name    Address   Dept_No    Status


4 Rajesh Jodhpur 20 AA

5 Pooja Nagpur 50 AA

6 Praveen Bhilai 20 AA


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response