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)
 Joining Id's from different database tables

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-06-17 : 19:23:37
select a.emp_id ,a.emp_name,b.phone,b.email,c.dept,c.course,d.address,e.scores,f.hobbies

from emp_details a ,contact b,Courses C ,property d,claims e ,personal F

Now I have a reference table where I have say 20-25 emp_id which is called emp_table

emp_table:
12
24
56
34
..
..
..
which have the emp_ids

Now all the tables used in the select statement have an emp_id which can be used to join between tables to pull according to the reference emp_id

Now in emp_details emp_id is emp_id
contact emp_id is Inc_id
property emp_id is Id
claims emp_id is C_id
personal emp_id is emp_id

Now I need to join all of then to get the corressponding records with
reference to the emp_id in the emp_table





derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-06-17 : 19:28:35
from emp_details a, contact b, Courses C

1. Don't do that. It's not correct syntax.
--Use FROM emp_details a INNER JOIN contact b ON a.emp_id = b.emp_id etc. etc.

2. Look at INNER JOIN and LEFT OUTER JOIN in Books Online. That will give you waht you are looking for. You should really look at SELECT in Books Online and figure out how it works also.

Have fun learning.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-06-17 : 19:29:51
from emp_table
join emp_details
on emp_table.emp_id = emp_details.emp_id
join contact
on emp_table.emp_id = contact.Inc_id
join ...


==========================================
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
   

- Advertisement -