BleepingComputer.com: collating records from different SQL Server tables

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

collating records from different SQL Server tables

#1 User is offline   BobLewiston 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 69
  • Joined: 07-November 08

Posted 16 March 2009 - 12:14 AM

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?

#2 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 16 March 2009 - 08:08 AM

Selecting a record from a database is SQL 101. W3Schools has a decent generic set of lessons for working with SQL.

The records are likely linked by the user id, although without seeing the actual columns of the table, I can't say for sure. Since several people could have the exact same contact address, it makes no sense to have the same address repeated over and over. The addresses are there once, and the names are linked to them. You will need to combine this:
http://www.w3schools.com/sql/sql_syntax.asp
with this:
http://www.w3schools.com/sql/sql_where.asp

EDIT: I am a little confused. In one thread, you say that you an not access a database programatically. This post seems to indicate that you can.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#3 User is offline   BobLewiston 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 69
  • Joined: 07-November 08

Posted 16 March 2009 - 09:39 AM

groovicus:

Thanks for the links; I'll check them out.

>I am a little confused. In one thread, you say that you an not access a database programatically. This post seems to indicate that you can.

I couldn't do it when I started that thread, now I can. It was partly a matter of finally getting the databases installed correctly, partly just learning how to access them correctly.

#4 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 16 March 2009 - 11:16 AM

So I can lock the other thread then?
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#5 User is offline   BobLewiston 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 69
  • Joined: 07-November 08

Posted 16 March 2009 - 11:57 AM

Yes. Sorry, I guess I should have mentioned the issue was resolved.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users