Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8425245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:13:04+00:00 2026-06-10T04:13:04+00:00

I have a table with data like the following id name created parent ————————————————

  • 0

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!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:13:06+00:00Added an answer on June 10, 2026 at 4:13 am

    Answered it myself!

    SELECT a.id, e.email 
    FROM account a 
             INNER JOIN emails.e 
                  ON e.account_id = IF(a.parent <> 0, a.parent, a.id)
    

    The thing I find with SQL is that there is always a more elegant way!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML structure like the following: <tables> <table name=tableName1> <row ID=34 col1=data
I have some data in a table that looks roughly like the following: table
I have a table with something like the following: ID Name Color ------------ 1
My table have data structure like this cate_id task_id date_start date_end other 34 14
I have a table that has data like below(sorted by date) COL_A | COL_B
I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
I have a table (call it table myTable). It has the data like this:
I have a data.table object like this one library(data.table) a <- structure(list(PERMNO = c(10006L,
I have a table called Addim and the data looks like: TName Idate Number
I'm a bit confused on this. I have a data table structured like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.