[eluser]FrankieShakes[/eluser]
[quote author="kgill" date="1192053283"]That join only covers to do half of what he wants, since he needs just the primary if they have it but otherwise everything else, I'd use a union and a subquery.
Code:
select x, y, z
from contact a, contact_tel_numbers b
where a.contact_id = b.contact_id
and b.primary_ind = 1
union
select x, y, z
from contact a, contact_tel_numbers b
where a.contact_id = b.contact_id
and a.contact_id not in (
select a.contact_id
from contact a, contact_tel_numbers b
where a.contact_id = b.contact_id
and b.primary_ind = 1
)
First select gets everyone who has a primary number set, next select grabs everybody else
- K[/quote]
Dude, you totally rock! That's what I was looking for! I had totally forgotten about "union". Truth be told, it's not something I used much in the past. I definitely need an SQL refresher.
Thanks so much, you saved me from pulling out my hair!
Quick question, if I wanted to add another "primary" field (from an email table), would I simply need to add another "union" query? Or is there more to it than just that?