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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:25:58+00:00 2026-05-31T21:25:58+00:00

The following is working as expected. It shows the default CPM and CPC for

  • 0

The following is working as expected. It shows the default CPM and CPC for the country if it is missing from the original table.
I am using a temporary table and I will like to know if it can be done without using temp table.

mysql> create temporary table country_list (country_name varchar(100));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into country_list values ('IN'), ('SA');
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

select dt.country_name as country, dt.operator,
if (dt.cpm is null, (SELECT cpm FROM ox_bidding_configuration where country = '' and operator = ''), dt.cpm) as updated_cpm,
if (dt.cpc is null, (SELECT cpc FROM ox_bidding_configuration where country = '' and operator = ''), dt.cpc) as updated_cpc,
if (dt.cpa is null, (SELECT cpa FROM ox_bidding_configuration where country = '' and operator = ''), dt.cpa) as updated_cpa
from (
select a.country_name, b.operator, cpm, cpc, cpa from country_list as a left join ox_bidding_configuration as b on a.country_name = b.country group by b.country, b.operator, cpm, cpc, cpa) as dt;
+---------+----------+-------------+-------------+-------------+
| country | operator | updated_cpm | updated_cpc | updated_cpa |
+---------+----------+-------------+-------------+-------------+
| SA      | NULL     |      1.0000 |      1.0000 |      1.0000 |
| IN      |          |      2.0000 |      2.0000 |      2.0000 |
| IN      | abcd     |     11.0000 |     23.0000 |      4.0000 |
+---------+----------+-------------+-------------+-------------+

The country SA is not in the primary table. So I can not use self left joins. I will like to know if there is a better way.

  • 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-31T21:26:00+00:00Added an answer on May 31, 2026 at 9:26 pm

    For starters, from where I’m standing you’re using the (temporary) country_list table as the PRIMARY table and match that against the ox_bidding_configuration where possible (left outer join); hence your result-set only contains the countries SA & IN.

    Although I’m not 100% sure this syntax works on MYSQL, being used to TSQL I would write your query as :

    SELECT dt.country_name as country, 
           dt.operator,
           COALESCE(dt.cpm, def.cpm) as updated_cpm,
           COALESCE(dt.cpc, def.cpc) as updated_cpd,
           COALESCE(dt.cpa, def.cpa) as updated_cpa
      FROM (SELECT DISTINCT a.country_name, 
                            b.operator, 
                            b.cpm, 
                            b.cpc, 
                            b.cpa 
              FROM country_list a
              LEFT OUTER JOIN ox_bidding_configuration as b
                           ON b.country = a.country_name ) dt
      LEFT OUTER JOIN ox_bidding_configuration def
                   ON def.country = '' 
                  AND def.operator = ''
    

    IMHO this is more clear, and probably it’s slightly faster too as the default config only needs to be fetched once.

    To get rid of the country_list table, you could convert it into an in-line query, but frankly I don’t see the benefit of it.

    Something along the lines of below :

    SELECT dt.country_name as country, 
           dt.operator,
           COALESCE(dt.cpm, def.cpm) as updated_cpm,
           COALESCE(dt.cpc, def.cpc) as updated_cpd,
           COALESCE(dt.cpa, def.cpa) as updated_cpa
      FROM (SELECT DISTINCT a.country_name, 
                            b.operator, 
                            b.cpm, 
                            b.cpc, 
                            b.cpa 
              FROM (SELECT 'SA'  AS country_name
                     UNION ALL 
                    SELECT 'IN') a
              LEFT OUTER JOIN ox_bidding_configuration as b
                           ON b.country = a.country_name ) dt
      LEFT OUTER JOIN ox_bidding_configuration def
                   ON def.country = '' 
                  AND def.operator = ''
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following section of code is working as expected... create table todel (id int
The following is working as expected. for schema in `mysql -eshow databases` do if
The following awk statement is working as expected. It returns 1st, 2nd and last
The following PHP code is working as expected. I need to echo copy error
The following jQuery is not working as expected. I'm simply trying to fire an
The following awk code is working as expected. I want to check if the
I'm working on SQLServer 2008 with the following table: id user program seconds ------------------------------------
I’m trying to get some code working using OData. The following bit of code
I have the following working tar -pcvf base.tar input/myPacket/my2 --exclude-vcs input/myPacket/my3/*.bmp When i have
In the following (working) code example, the templated register_enum() function is used to iterate

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.