|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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' |
|
#3
|
|||
|
|||
|
Quote:
Last edited by elyk : July 11th, 2003 at 03:03 PM. |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > default addresses in addressbook |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|