collating records from different SQL Server tables

BobLewiston

In Runtime
Messages
182
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?
 
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.
 
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
customerID
Name
Address

then you have a table called orders.
this table has columns
orderID
Order_contents
customer

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.
 
Back
Top Bottom