Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Left Outer Join

Author  Topic 

prompratan
Starting Member

30 Posts

Posted - 2005-01-03 : 05:00:43
emp_table
------------
id * name
1001 * a
1002 * b
1003 * c

time_table
--------------------
id * t_id
1001 * 01
1002 * 02

t_table
------------
t_id * times
01 * 8:00
02 * 11:00


I want Result is
Result_table
-----------------------------------------------------------
id * name * t_id * times
1001 * a * 01 * 8:00
1002 * b * 02 * 11:00
1003 * c * NULL * NULL



* is separate for fields and data

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-03 : 05:14:21
select e.id, e.name, t.t_id, tt.times
from emp_table e
left join time_table t
on e.id = t.t_id
left join t_table tt
on t.t_id = tt.times
order by e.id

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

prompratan
Starting Member

30 Posts

Posted - 2005-01-03 : 20:21:10
Thank you for Question nr
Go to Top of Page

prompratan
Starting Member

30 Posts

Posted - 2005-01-03 : 20:42:22
I have any questions. If I want Result is

Result_table
-----------------------------------------------------------
id * name * t_id * times
1003 * c * NULL * NULL

I should write sql ???
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-03 : 21:27:36
select e.id, e.name, t.t_id, tt.times
from emp_table e
left join time_table t
on e.id = t.t_id
left join t_table tt
on t.t_id = tt.times
where t.t_id is null
order by e.id

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

prompratan
Starting Member

30 Posts

Posted - 2005-01-03 : 21:52:01
Thank you very much
Go to Top of Page
   

- Advertisement -