hi,
I have some problem in sql query. I have 2 table with data like--
Table1
id Project_id Emp_id Task_Name status
282 70 ,42,43,44, abcd 1
244 60 ,42,34, xyz 2
Table2
id Emp_id Project_id module
1 42 ,70,60, ,282,244,
2 43 ,60,70 ,282,
This is my two table but i want a Query which will show me the record id ,project_id, Task_Name status
one condition is there. if Table1 id and Project_id is present in the Table2 then status 1 will show ON . if id and Project_id not present then status2 will show OFF in Table2
Loading

Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 12, 2013, 2:25 AM EDT
Hi,
I think, in this case Left outer join can help you to resolved your problem.
try..
Select t1.id ,t1.project_id, t1.Task_Name, t1.status, Case when t2.project_id is null then 'OFF' else 'ON end as status1
from table1 t1
left outer join table2 t2 on t1.project_id = t2.project_id and t1.emp_id = t2.emp_id
hope this will help you.
ranjan sahooRank #5,709 · 289 reputationPosted Sep 12, 2013, 3:05 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 12, 2013, 4:07 AM EDT
hi,
The LEFT JOIN returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match.
The RIGHT JOIN returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match.
The FULL OUTER JOIN returns all rows from the left table (table1) and from the right table (table2).
Please refer
http://www.programmerinterview.com/index.php/database-sql/difference-between-a-left-outer-join-and-right-outer-join/
hope this will help you.
Suthish NairRank #92 · 22.8K reputationPosted Sep 12, 2013, 4:59 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Sep 13, 2013, 3:36 AM EDT
ranjan sahooRank #5,709 · 289 reputationPosted Sep 14, 2013, 2:14 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Sep 17, 2013, 12:10 AM EDT