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 > Database Server Software > MySQL > Example needed for mysql field setup

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-07-10, 13:30
acctman acctman is offline
Registered User
 
Join Date: Aug 2008
Posts: 4
Example needed for mysql field setup

Can someone explain the below statement to me with an example/sample... basically what i'm trying to do is handle a member couple profile which will have multiple Firstnames, Age, Height, etc about 10 fields will be similar.

You could create duplicate fields, but simply add a single extra field, "coupleId", which would have a unique id for each couple; and two rows (one for each person) per couple; then JOIN the table against itself with a constraint like a.coupleId = b.coupleId AND a.id <> b.id so that you can condense the data into a single result row for a given couple.
Reply With Quote
  #2 (permalink)  
Old 04-15-10, 05:56
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
I am not following what you are asking here? What is a member couple profile? Are you saying that two members join up as a couple and you want to have both members details appearing on a single returned row?
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 04-15-10, 10:36
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
acctman, if you look at it a little more closely, the answer was "you could not create duplicate fields..."

obviously the table for the people would have one row per person, and you would not want duplicate columns in there

the simplest solution, and in my mind the most elegant, is a separate table, which contains only two columns, the ids of the two people who are dating

members
204 john smith 42
206 mary white 27
213 todd kamalfeszchuk 37
221 linda brown 28
242 betty boop 45

couples
204 242
206 213

one of the other questions that always comes up in this database design is how do i prevent duplication, e.g. if john and betty are dating, how do i ensure that i don't have john and betty in the database along with betty and john?

the answer to that is simple, too -- always store the ids with the lower one first
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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