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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:08:39+00:00 2026-05-12T17:08:39+00:00

I have a database with questions and answers that get translated into all languages

  • 0

I have a database with questions and answers that get translated into all languages that site is used by. But when a question is not translated yet I want to show that question in english language. So a gettext-like behavior.

My current SQL query for this looks like this:

SELECT * FROM questions_view WHERE `language` = "de" AND `#parent` IS NULL
UNION 
SELECT * FROM questions_view WHERE `language` = "en" AND `#parent` IS NULL 
    AND id NOT IN (SELECT id 
                   FROM questions_view 
                   WHERE `language` = "de")

But I feel like this is not the optimal way of doing this. Any tips?

  • 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-12T17:08:40+00:00Added an answer on May 12, 2026 at 5:08 pm

    This:

    SELECT  qi.*
    FROM    (
            SELECT  DISTINCT id
            FROM    questions_view
            ) qd
    JOIN    questions_view qi
    ON      qi.id = qd.id
            AND qi.language =
            COALESCE(
            (
            SELECT  language
            FROM    questions_view qn
            WHERE   parent IS NULL
                    AND language = 'de'
                    AND qn.id = qd.id
            ),
            (
            SELECT  language
            FROM    questions_view qn
            WHERE   parent IS NULL
                    AND language = 'en'
                    AND qn.id = qd.id
            )
            )
    

    or this:

    SELECT  COALESCE(qde.question_text, qen.question_text)
    FROM    (
            SELECT  DISTINCT id
            FROM    questions_view
            ) qd
    LEFT JOIN
            questions_view qde
    ON      qde.id = qd.id
            AND qde.language = 'de'
    LEFT JOIN
            questions_view qen
    ON      qen.id = qd.id
            AND qen.language = 'en'
    

    Which if these queries is better depends on you database system and on how many questions in your database are translated.

    See this series of articles in my blog for more detail:

    • Fallback language names: Oracle
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataset that returns questions and answers from the database, each answer
My database contains both questions and answers. The questions have an ID (intQAID) and
I have a MS access database. In that, one table consists of questions and
Another basic Rails question: I have a database table that needs to contain references
I've read the questions/answers saying that Java doesn't have nor is it likely to
I have two tables question and answers. - questions{id,user_id,question,date} - answers {id,q_id,user_id,answer, date} I
Now that I have read an awfull lot of posts, articles, questions and answers
There have been similar questions but the answers weren't what I was looking for.
i have this PHP code, and a DataBase with Question, answer1, answer2, Question_id well,
basically i have a database, which contains a random amount of questions i have

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.