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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:26:08+00:00 2026-06-04T05:26:08+00:00

This is a quite delicate question, but I’ll give my best to make it

  • 0

This is a quite delicate question, but I’ll give my best to make it clear:

I have a table countrynames with 3 columns: iso, lang, name.
The main spelling for these is english, for example:

+-----+------+-----------------------------+
| iso | lang | name                        |
+-----+------+-----------------------------+
| CA  | EN   | Canada                      |
| CC  | EN   | Cocos (Keeling) Islands     |
| CF  | EN   | Central African Republic    |
| CG  | EN   | Congo                       |
| CI  | EN   | Cote d'ivoire (Ivory Coast) |
| CK  | EN   | Cook Islands                |
| CL  | EN   | Chile                       |
| CM  | EN   | Cameroon                    |
| CN  | EN   | China                       |
| CO  | EN   | Colombia                    |
+-----+------+-----------------------------+

iso is the foreign key which references the iso-3166 coding for countries.

I inserted a number of countries with english spelling, but also in other languages ONLY when the spelling is different from english, in order to save some space in the database (for example “Germany” in german is “Deutschland”, so the iso for ‘DE’ appears twice in the table, with 2 different names).

What I need is to select all the countries in some specific language (like german, or spanish), then all countries with english names from the same column. Where there is no corresponding name in the foreign language, then the english name should fill the empty field, so that I get a mixture of english + foreign language. The mixture should be equal to the sum of countries with english spelling, like this (nulls are where the english names should fill the missing spanish names, like Congo, Chile, China, Colombia):

'CA', 'ES', 'Canadá'
'CC', 'ES', 'Islas Cocos'
'CD', 'ES', 'República Democrática del Congo'
'CF', 'ES', 'República Centroafricana'
NULL, NULL, NULL
'CH', 'ES', 'Suiza'
'CI', 'ES', 'Costa del Marfil'
'CK', 'ES', 'Islas Cook'
NULL, NULL, NULL
'CM', 'ES', 'Camerún'
NULL, NULL, NULL
NULL, NULL, NULL
NULL, NULL, NULL
NULL, NULL, NULL

This is what I used so far:

select result2.iso, result2.lang, result2.name from (select result1.* from (select  t1.*
from (
select iso, lang, name from countrynames where lang = 'es') t1
right join
(select iso, lang, name from countrynames where lang = 'en') t2
on t1.iso = t2.iso) result1) result2;
  • 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-04T05:26:10+00:00Added an answer on June 4, 2026 at 5:26 am

    Your original SELECT can be simplified a little:

    SELECT t1.iso, t1.lang, t1.name
      FROM (SELECT * FROM countrynames WHERE lang = 'ES') t1
      RIGHT JOIN (SELECT * FROM countrynames WHERE lang = 'EN') t2
      ON t1.iso = t2.iso;
    

    Then all you need do is coalesce the column results, so you retrieve the t2 values if there are no values in t1:

    SELECT COALESCE(t1.iso, t2.iso), COALESCE(t1.lang, t2.lang), COALESCE(t1.name, t2.name)
      FROM (SELECT * FROM countrynames WHERE lang = 'ES') t1
      RIGHT JOIN (SELECT * FROM countrynames WHERE lang = 'EN') t2
      ON t1.iso = t2.iso;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been asked this question and have given this quite some thought but
I feel like this is quite delicate, I have various folders whith projects I
I have this quite popular problem, but have failed to find a solution that
I am currently learning regex but need this quite urgently. I have a set
sorry if this quite a easy question, but i cant find any thread the
I have this quite long query that should give me some information about shipments,
I know this might be a common question but I have tried to search
I've edited this quite a bit and bolded my question at this point. I
This is quite the pickle... I have a regular HTML form with a couple
This is quite a simple question - although one that is on my mind

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.