MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 26th, 2003, 01:48 PM
method method is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 method User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
HELP joining two tables

Hello,

I am creating a view that displays service codes and descriptions. I have two tables. Table 1 has service codes and table 2 has service code and description.

all of the fields in table 1 are dependant on table 2.

For example

Table 1

service_code1
service_code2
sevice_code3

Table 2

service_code
service_code_description

How can I join all three service codes from table 1 to table 2 to get each individual service code description?

service_code1
service_code_description1

service_code2
service_code_description2

service_code3
service_code_description3

Reply With Quote
  #2  
Old August 26th, 2003, 03:36 PM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 11
Send a message via AIM to unatratnag
how about you explain a little better and give us a few real values. Table one sounds completely erroneous if it's redundant in the primary key in table two.
this is what i'm pictureing
Code:
table 1              table 2
servcode          servcode         desc
123                   123                  blah
463                   463                  blah
987                   967                  blah


are certain descriptions missing where you have something in table 1 but nothing in table 2 and you want to know how to join these tables keeping the values in table 1 even though you have no entry in 2? Perhaps i just didn't understand your schema explanation....

Reply With Quote
  #3  
Old August 26th, 2003, 03:38 PM
WineIsGood's Avatar
WineIsGood WineIsGood is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: New York
Posts: 49 WineIsGood User rank is Private First Class (20 - 50 Reputation Level)WineIsGood User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 m 51 sec
Reputation Power: 10
Include the same description table three times. You can do this by using aliases, like this:

SELECT
a.Service_code1, b.Service_code_description,
a.Service_code2, c.Service_code_description,
a.Service_code3, d.Service_code_description
FROM table1 a, table2 b, table2 c, table2 d
WHERE
a.Service_code1=b.Service_code
AND a.Service_code2=c.Service_code
AND a.Service_code3=d.Service_code

-Dave

Reply With Quote
  #4  
Old August 26th, 2003, 03:44 PM
method method is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 method User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hmm,

table 1 contains three different service code fields.

exterior_service_code1 <--- contains 100 distinct codes
interior_service_code2 <--- contains 50 distinct codes
misc_service_code3 <--- contains 25 distinct codes

table 2 contains all of the descriptions for each code

service_code <--------contains all codes (exterior_service_code1, interior_service_code2 and misc_service_code3) <--- contains 175 distinct codes

serivice_description <-- contains 175 distinct descriptions

so the three fields get their description from table 2

does this help?

Last edited by method : August 26th, 2003 at 03:52 PM.

Reply With Quote
  #5  
Old August 27th, 2003, 08:32 AM
method method is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 method User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by WineIsGood
Include the same description table three times. You can do this by using aliases, like this:

SELECT
a.Service_code1, b.Service_code_description,
a.Service_code2, c.Service_code_description,
a.Service_code3, d.Service_code_description
FROM table1 a, table2 b, table2 c, table2 d
WHERE
a.Service_code1=b.Service_code
AND a.Service_code2=c.Service_code
AND a.Service_code3=d.Service_code

-Dave


PERFECT! thanks Dave!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > HELP joining two tables

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap