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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:48:24+00:00 2026-05-20T00:48:24+00:00

I have two product tables. Table A is the default table (comes from data

  • 0

I have two product tables. Table A is the “default” table (comes from data feed is automatically updated weekly). Table B is used to manually overwrite the values in Table A and has the same columns as Table plus a few more. Both tables always have the same UniqueID column.

I need a select statement that pulls all the values from A and all the values from B, with B overwriting the values from A UNLESS the value from B is null, = to 0 or equal to 0.00 (column set to integer with 2 decimal points and been filled with “0”).

I tried using a LEFT JOIN but am having trouble with the null and “0” values.

I am using the data in php and can deal with it when I only need to pull in 1 row. I query for each, extract the assoc array for A, filter the B array and then extract it. But that process becomes very clunky when start to pull in 20-200 rows.

Table A has about 400,000 rows and can’t see B getting over 10,000-20,000.

Thanks for your help.

UPDATE: Here is the code I got to work.

SELECT a.UniqueId,
IF(b.Color, b.Color, a.Color) as Color,
IF(b.Price1 = 0, a.Price1, b.Price1) as Price1,
b.SPrice1
FROM productdata a LEFT JOIN product_overrides b ON a.UniqueID = b.UniqueID WHERE a.UniqueID = $prod";

UPDATE 2: So simple is better. IF() addresses both null and zero.

IF(expr1,expr2,expr3)

If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns expr2; otherwise it returns expr3. IF() returns a numeric or string value, depending on the context in which it is used.

SELECT a.UniqueId,
IF(b.Color, b.Color, a.Color) as Color,
IF(b.Price1, b.Price1, a.Price1) as Price1,
b.SPrice1
FROM productdata a LEFT JOIN product_overrides b ON a.UniqueID = b.UniqueID WHERE a.UniqueID = $prod";

  • 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-20T00:48:25+00:00Added an answer on May 20, 2026 at 12:48 am

    I think this aught to cover all your scenarios:

    SELECT 
       COALESCE(b.nullablefield, a.nullablefield) as nullablefield,
       IF(b.intfield = 0, a.intfield, b.intfield) as intfield,
       IF(b.floatfield = 0, a.floatfield, b.floatfield) as floatfield,
       ... etc ...
    FROM table_a a
    LEFT JOIN table_b b ON a.UniqueID = b.UniqueID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two identical tables and need to copy rows from table to another.
I have two tables as follows PRODUCT table Id | Name | Price And
ok here is it. i have two tables: products and warehouse product table consist
I have two tables, categories and products. I am using CodeIgniter. Categories CREATE TABLE
I have two tables users and lead_contacts which have similar data. When somebody buys
I have two tables: CREATE TABLE 'sales_sheet' ( `_id` int(11) NOT NULL AUTO_INCREMENT, `_typed_by`
I have two tables: A (col1,col2,col3,col4) B (col1,col2,col3,col4) Table A has 4 records(rows) and
I have two tables: Product ------------------------------------ id group_id name quick_select ------------------------------------ 1 1 product1
Ok say I have two tables Product and Sales The product contains the id,
I have two tables TABLE A and TABLE B. TABLE A contain 1 million

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.