Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 11th, 2003, 01:05 AM
elyk elyk is offline
Thread Killer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Missouri
Posts: 41 elyk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Question default addresses in addressbook

I am building an address book in MySQL with a many-to-many join.

Table 1:
name
id

Table 2:
email address
id

table 3:
table1.id
table2.id

If a person has more than one address, I want to add a field somewhere, probably in table 2 or 3, to specify that the certain email address is the default address. How would I implement this? How would I enforce that only one address per person would be default? What SQL would I need to retrieve only a default email address and not all addresses for a person?

Reply With Quote
  #2  
Old July 11th, 2003, 07:58 AM
a.koepke's Avatar
a.koepke a.koepke is offline
Second highest poster :p
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jul 2001
Posts: 7,323 a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 8 m 45 sec
Reputation Power: 27
Okay... why are you doing a many to many... how many cases are there going to be of the email address going to many names? Just do a one to many link.

Table 1
name_id
name

Table 2
email_id
name_id
email_address
default

Make the default a boolean field and have true to denote default address.

The SQL you need is

SELECT t1.name, t2.email_address FROM Table1 as t1, Table2 as t2 WHERE t1.name_id=t2.name_id AND t2.default='true'

Reply With Quote
  #3  
Old July 11th, 2003, 02:51 PM
elyk elyk is offline
Thread Killer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Missouri
Posts: 41 elyk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Quote:
Okay... why are you doing a many to many... how many cases are there going to be of the email address going to many names? Just do a one to many link.
This is why I don't like the windows address book. I started to make my own, but I came up with this problem.

Last edited by elyk : July 11th, 2003 at 03:03 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > default addresses in addressbook


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway