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
Suthish NairPosted Sep 17, 2013, 4:10 AM
ranjan sahooPosted Sep 14, 2013, 6:14 AM
Suthish NairPosted Sep 13, 2013, 7:36 AM
Suthish NairPosted Sep 12, 2013, 8:59 AM
Jignesh TrivediPosted Sep 12, 2013, 8:07 AM
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.
ranjan sahooPosted Sep 12, 2013, 7:05 AM
Jignesh TrivediPosted Sep 12, 2013, 6:25 AM
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.