If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > "Friend of a friends" concept design

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-22-07, 21:03
rca420 rca420 is offline
Registered User
 
Join Date: Dec 2005
Posts: 5
"Friend of a friends" concept design

Hey all,

I'm currently designing a database in MYSQL as a learning experience, but I'm stuck at designing a function similar to facebook's "Friend of a friend of a friend" design (What's the correct terminology?). Where I am connected to Jim Bob from New York through Mary Ann in Washington DC. Please advise. Any help is much appreciated! Thanks
Reply With Quote
  #2 (permalink)  
Old 01-22-07, 23:06
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
terminology? i would say "friend of a friend" is descriptive enough

you'll need a table of people, yes? with name, age, hatsize, etc.

and you'll need another table of relationships, to relate person1 to person2, so this table will have two columns, the ids of the two people involved

load up some data and see if you can figure out the sql necessary to retrieve the related names
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-07-07, 18:31
bdimple bdimple is offline
Registered User
 
Join Date: Jul 2003
Posts: 74
How about Prisoners and Associates ...

This Data Model on the Database Answers web site might provide some insights :-
http://www.databaseanswers.org/data_...ners/index.htm

HTH

B.Dimple
Senior DBA
Reply With Quote
  #4 (permalink)  
Old 02-07-07, 18:55
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
the operative word being might

i would argue vehemently against the columns prison_staff_id and prisoner_offence_id

sometimes, a totally superfluous key, like those two, is argued as being necessary as the parent key of a child of the association

but notice those two don't have child tables

the one association table that does have a child table, prisoner_associates, why, it uses (correctly, in my opinion), a compound natural key

who'd've thunk it! you got to take those designs what you find on them internets with a grain of salt!

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-08-07, 14:02
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
true.

IMO, an intersection table has no need of a surrogate primary key - the compound Primary Key serves perfectly. (after all, even iIF you added an unnecessary surrogate PK, you would STILL need to define a unique key for the two foreign keys)
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert

Reply With Quote
Reply

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On