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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:53:17+00:00 2026-05-22T19:53:17+00:00

I am attempting to perform an inner join on two tables so that I

  • 0

I am attempting to perform an inner join on two tables so that I can round a value by the precision associated with that value’s pid in the other table. However, it is returning NULL for pid 3. I believe it has to do with the NULL precision for pid 2, because when I set it’s precision to a non-NULL value, I get the correct value for pid 3 in the query below.

How can I restructure this query so that it will always return the correct value even if another pid contains a NULL precision?

select pid_values.pid, pid_values.value, round(value, pids.precision) 
from pid_values inner join pids on pid_values.pid = pids.pid;

+------+--------+------------------------------+
| pid  | value  | round(value, pids.precision) |
+------+--------+------------------------------+
|    1 | 10.123 |                           10 |
|    2 |    5.5 |                            6 |
|    3 | 3.1234 |                         NULL |
+------+--------+------------------------------+

Data in both tables:

select * from pids;
+------+-----------+
| pid  | precision |
+------+-----------+
|    1 |         0 |
|    2 |      NULL |
|    3 |         1 |
+------+-----------+

select * from pid_values
+----+------+--------+
| id | pid  | value  |
+----+------+--------+
|  1 |    1 | 10.123 |
|  2 |    2 |    5.5 |
|  3 |    3 | 3.1234 |
+----+------+--------+
  • 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-05-22T19:53:18+00:00Added an answer on May 22, 2026 at 7:53 pm

    Try this query:

    SELECT 
      pid_values.pid, 
      pid_values.value, 
      round(value, IF(pids.precision IS NULL, 0, pids.precision)) 
    FROM pid_values INNER JOIN pids ON pid_values.pid = pids.pid;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to perform a full outer join on two tables that are not
This is driving me nuts. I have two tables that I am attempting to
I'm attempting to perform dynamic sorting of data that I'm putting into grids into
I am attempting to perform integration testing on services that I have developed. Part
I am attempting to build a system that allows users to perform certain actions,
I'm attempting to find an example that demonstrates a Lucene or some other kind
I am attempting to perform a Storyboard segue from a UIbutton that is a
I'm attempting to construct a function that will perform a sanity check on the
I'm attempting to perform a DML operation against an Entity Framework model, specifically, an
I've been attempting to write a Lisp macro that would perfom the equivalent of

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.