select Name,Address from Employee e
left join Department d on e.EmpId =d.EmpId
where e.Status =1
----------------------------------------------------
create table Employee
(
EmpId int,
Name varchar(100),
Address varchar(100),
Status bit
)
insert into Employee(EmpId,Name,Address,Status) values (1,'Ashish','chandigarh',1), (2,'Pankaj','Ghaziabad',1), (3,'Rahil','Delhi',1)
create table Department
(
ID int,
EmpId int,
DeptName varchar(100)
)
insert into Department(ID,EmpId,DeptName) values (1,1,'IT'), (2,2,'Bank'), (5,5,'CA')
var query = (from e in Employees
join d in Departments on e.EmpId equals d.EmpId into tmp
from t in tmp.DefaultIfEmpty()
where e.Status == true
select new
{
Name = e.Name,
Address = e.Address
}).ToList();
query.Dump();
left join Department d on e.EmpId =d.EmpId
where e.Status =1
----------------------------------------------------
create table Employee
(
EmpId int,
Name varchar(100),
Address varchar(100),
Status bit
)
insert into Employee(EmpId,Name,Address,Status) values (1,'Ashish','chandigarh',1), (2,'Pankaj','Ghaziabad',1), (3,'Rahil','Delhi',1)
create table Department
(
ID int,
EmpId int,
DeptName varchar(100)
)
insert into Department(ID,EmpId,DeptName) values (1,1,'IT'), (2,2,'Bank'), (5,5,'CA')
var query = (from e in Employees
join d in Departments on e.EmpId equals d.EmpId into tmp
from t in tmp.DefaultIfEmpty()
where e.Status == true
select new
{
Name = e.Name,
Address = e.Address
}).ToList();
query.Dump();
No comments:
Post a Comment