Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 03-16-2009, 12:17 AM   #1
Baseband Member
Join Date: Nov 2008
Posts: 91
Default collating records from different SQL Server tables

I'm starting to learn SQL Server. As part of that effort, I'm experimenting with accessing AdventureWorks sample databases.

In database AdventureWorks, I've been accessing table Person.Contact. Although in that table there are columns for a phone number and an email address, there are no columns for a postal address. I see columns for a postal address in table Person.Address, but in that table there is no column for a numerical value ContactID, or for a string value for the contact's name, as there is in table Person.Contact.

It seems to me, especially because each of these two tables' names start with "Person.", that these tables are somehow linked. However, I don't see any columns in either table which seem to allude to any other tables. For what it's worth though, each of the two tables has a column called "rowguid", the purpose of which I don't understand.

I'd like my app to display in a WinForm all the information available for each contact, but I don't know how to locate the Person.Address record corresponding to a given Person.Contact record. Can anybody tell me how to do this?

BobLewiston is offline   Reply With Quote
Old 03-16-2009, 03:13 AM   #2
Fully Optimized
–88's Avatar
Join Date: May 2005
Posts: 4,775
Send a message via MSN to –88
Default Re: collating records from different SQL Server tables

I've noticed you've been asking a lot of questions about SQL but haven't gotten any responses. It doesn't look like there is anyone knowledgeable enough or maybe willing to help you with your questions. But I suppose if you want to continue asking maybe someone who can answer them will eventually come by. I wish I could help ya but i've had very little experience with server use and administration.

Killing under the cloak of war is no different than murder

Kein Alkohol ist auch keine LŲsung!
–88 is offline   Reply With Quote
Old 03-16-2009, 06:06 AM   #3
Site Team
root's Avatar
Join Date: Mar 2004
Posts: 8,098
Default Re: collating records from different SQL Server tables

you need to join tables,

There are inner joins and outer joins...

I don't know the database that you;re talking about.

so lets have an imaginary scenario

you have a database called business.

there is a table called customers
this table has columns

then you have a table called orders.
this table has columns

To find out what customers match to what orders use the statement

Select customerID, name, address, orderID, order_contents
from customers, orders
where customers.customerID = orders.custmer

you have order number 10045 and need to know the address to deliver it to

in this case you use te following SQL statement

select customerID, name, address, order_contents
from customers, orders
where customers.customerID = orders.customer
and order_ID = '10045'

In your table, you should find something that matches, personID or something.

rowguid doesn't sound like the most intuitive name, but the letters UID usually means unique ID, so this just may be the column you;re meant to use.
I didnít fight my way to the top of the food chain to be a vegetarianÖ
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 08:29 AM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0