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
 SQL Server Development (2000)
 joining the two tables

Author  Topic 

Anjani
Starting Member

2 Posts

Posted - 2009-05-28 : 05:47:31
Hi,

I like to write the query which joins the two tables.

I am having two tables named Employee and Dependents.

In employee table having columns empid,empname.

In Dependents table having columns empid,name,email_id,phonenum.

I want to the join the tables and in my final table i want all the

columns from both the tables.

plz help me in writing the query....

Thanks in advance




Anjani

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-28 : 06:04:38
[code]
select *
from employee e inner join dependents d
on e.empid = d.empid
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-05-30 : 08:41:26
If you want to show all records even if there is no matching record in dependents:
select *
from employee e left join dependents d
on e.empid = d.empid



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-30 : 08:47:57
Although you want all the columns from both the tables, dont use *. Instead explicitely name the columns with prefixing the table aliases

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -