I have a table with data like the following
id name created parent
------------------------------------------------
1 Alpha 11385209583 0
2 Bravo 11385209619 0
3 Bravo-A 11385209701 2
4 Bravo-B 11385209777 2
such that Bravo-A and Bravo-B are children of Bravo.
There is another table with email addresses in it (accounts a JOIN emails e ON a.id = e.account_id), but only parent accounts have emails. That is to say, Bravo-A’s email is Bravo’s.
If I have the accounts.id number, is it possible to write a query that would give me the emails.email field for the correct account (where account_id = 1 when id is 1, account_id = 2 when id is 2, 3, or 4)?
(My apologies if this is a little verbose or not to the point, I was having trouble verbalizing it!)
Answered it myself!
The thing I find with SQL is that there is always a more elegant way!