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 8181809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:38:55+00:00 2026-06-07T00:38:55+00:00

I currently have a table of concentrations, which are linked to a table of

  • 0

I currently have a table of concentrations, which are linked to a table of elements. There is a concentration table

|conc_id|element_id|conc|

and and element table

|element_id|symbol|

The concentration table only has element_ids for each conc_id that have non-zero concentrations.
What I am trying to do is create a query which will, for each concentration_id, list all the elements in order, with their concentration, regardless of whether they’re non-zero or not. I have tried this in a number of increasingly complicated ways (starting with a RIGHT JOIN) but this always outputs a NULL conc_id when there is none of that element in it. The output I am looking for is something like this:

|conc_id|element_id|symbol|conc|
|1      |1         |H     |1.2 |
|1      |2         |He    |NULL|
|1      |3         |Li    |2.3 |
              ...
|3      |1         |H     |4.5 |
|3      |2         |He    |NULL|
|3      |3         |Li    |NULL|
              ...

And so on. Is there a way I can do this without having NULL conc_id?

Thanks for any help in advance…

  • 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-07T00:38:55+00:00Added an answer on June 7, 2026 at 12:38 am

    First, you have to build a table that contains all combinations between conc_id and element_id:

    SELECT DISTINCT conc_id, elements.element_id FROM concentrations, elements;
    

    Which gives you the following table:

    | conc_id | element_id |
    |       1 |          1 |
    |       1 |          2 |
    |       1 |          3 |
                ...
    |       3 |          1 |
    |       3 |          2 |
    |       3 |          3 |
                ...
    

    Once you have such a table, joining it with concentrations and elements should be fairly simple. For example:

    SELECT combinations.conc_id, combinations.element_id, symbol, conc
    FROM 
      (SELECT DISTINCT conc_id, elements.element_id FROM concentrations, elements) AS combinations
      LEFT JOIN concentrations ON (combinations.conc_id = concentrations.conc_id AND combinations.element_id = concentrations.element_id)
      LEFT JOIN elements ON (combinations.element_id = elements.element_id);
    

    Result:

    | conc_id | element_id | symbol | conc |
    |       1 |          1 | H      |  1.2 |
    |       1 |          2 | He     | NULL |
    |       1 |          3 | Li     |  2.3 |
                      ...
    |       3 |          1 | H      |  4.5 |
    |       3 |          2 | He     | NULL |
    |       3 |          3 | Li     | NULL |
                      ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a table which only has a single editable column. I have
I currently have a table called paper , which holds all the information for
I currently have a table which stores a load of statistics such as views,
I currently have a table which looks like this: Users username address dob ...
I currently have a dropdown box which enters an integer into a table. It's
I currently have a table that exists which I'm able to pull data from.
I currently have a table which has these columns: id (INT) parent_id (INT) col0
I currently have a table which represents the start and stop work times of
I currently have a table called User which has a id column which is
Hi I currently have a table view which is being filled via Core Data.

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.