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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:23:38+00:00 2026-05-27T03:23:38+00:00

The key of table items is comprised of ( lang , id ). Some

  • 0

The key of table items is comprised of (lang, id). Some items have a translated name in different languages. I want to create such a query that would return all the items from the DB in a given language and if an item doesn’t have a translation to return the untranslated value.

Say I want to get all items written in Bulgarian. This is where I’m stuck:

SELECT lang, id, name
FROM items
WHERE lang = "bg" OR lang = "en"
GROUP BY id

The problem arises when there is an item, say, (1, “en”) and an item (1, “bg”). The ids are the same. Then how does MySQL or SQLite determine which result to return? Is there any way I can tell it that I would rather prefer to return (1, “bg”) if it exists but if it doesn’t then (1, “en”) would satisfy me?

P.S.
To further illustrate what I want let’s imagine that the database contains the following entries with schema (id, lang, name):

(1, “en”, “abc”)

(2, “en”, “cde”)

(3, “en”, “def”)

(1, “bg”, “абв”)

(3, “bg”, “жзи”)

After executing the desired query for Bulgarian I should get:

(1, “bg”, “абв”)

(2, “en”, “cde”)

(3, “bg”, “жзи”)

  • 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-27T03:23:39+00:00Added an answer on May 27, 2026 at 3:23 am

    If “untranslated” means “English” or in other words, the base language is English, you can LEFT join the table to itself and use COALESCE() function to get rid of NULL values

    SELECT COALESCE(bg.lang, en.lang) AS lang
         , en.id                      AS id
         , COALESCE(bg.name, en.name) AS name
    FROM items en
      LEFT JOIN items bg
        ON  bg.id = en.id
        AND bg.lang = 'bg'
    WHERE en.lang = 'en'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table full of items from different sources. Some of the sources
I have a composite primary key table (Maintenance Items). I would like to create
In an sqlite3 -console: sqlite> CREATE TABLE items (id PRIMARY KEY); BEGIN; SELECT *
I have two tables: CREATE TABLE items ( root_id integer NOT NULL, id serial
This code: conn = connect('emails.db') curs = conn.cursor() curs.execute('''create table items (integer primary key,
Suppose I have a table Item (Id int Primary Key, Number INT) having records
Lets Say i have a table like this WEB_LIST_TABLE KEY Value ---------------------------------------- 134 google.com
i have a table called Cars and the primary key of the table is
I have two table. One table hold key column and xml column. Other table
i am trying to create a foreign key in my table. But when i

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.