mysql - SQL efficiency join on two fields or one -


let have got 3 tables: account, contact , address. account , contact want assign multiple addresses. better have 2 fields in address join_type , join_id , example running query:

select a.* address inner join contact c on c.id = a.join_id , a.join_type = 'contact'; 

and

select a.* address inner join account ac on ac.id = a.join_id , a.join_type = 'account'; 

or have account_id , contact_id instead of join_type , join_id , running query:

select a.* address inner join contact c on c.id = a.contact_id; 

and

select a.* address inner join account ac on ac.id = a.account_id; 

or maybe have got 2 seperate address tables account , contact? first option best future if e.g. have addresses assigned users.

select a.* address inner join contact c on c.id = a.contact_id;

the fact have multiple types of addresses should not cause problem since contact_id should unique.

i consider having column in address account_id , have join this:

select a.* address inner join account on a.id = a.account_id;


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -