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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:17:52+00:00 2026-05-26T05:17:52+00:00

I have a MySQL SQL query that selects products and the text translations: SELECT

  • 0

I have a MySQL SQL query that selects products and the text translations:

SELECT *
FROM (select * from products) p
LEFT JOIN (SELECT * FROM translations) t
ON t.id = p.product_id

This grabs the products from the database. However it grabs all the available translations. I just want to get the translations in the current language. So i can use this:

SELECT *
FROM (select * from products) p
LEFT JOIN (SELECT * FROM translations WHERE lang = 'en') t
ON t.id = p.product_id

This works as intended, however not all products have a translation for every language. What I ultimately want to do is specify a language and if there is no given translation then return whatever other translations we have. Can this be done in SQL or am i going to need to iterate through the results in PHP?

  • 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-26T05:17:52+00:00Added an answer on May 26, 2026 at 5:17 am

    If you create a ‘default’ language translation for each product, and give it code 'zz' then the following will work. There must be a 'zz' translation for every product.

    (This took me literally an hour, but I’ve learned a lot in the process – great question!).

    SELECT *
    FROM products p
    LEFT JOIN translations t
    ON (p.id == t.product_id
        AND (t.lang == 'en'
             OR (t.lang == 'zz' AND
                 'en' NOT IN
                 (SELECT `lang` FROM translations t2 WHERE t2.product_id == p.id)
                )
            )
       );
    

    Sorry if it’s not efficient. You’ll need to try it out and see.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL query like this: SELECT *, SUM(...some SQL removed for brevety)
I have a query that selects some fields to display from a table SELECT
I have a MySQL query that selects data from multiple tables and then orders
Does Microsoft Access have Full Text Search? I know that MySQL and SQL Server
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
I have a .sql file from a MySQL dump containing tables, definitions and data
I have this code, $sqlstr = mysql_query( SELECT * FROM sales where passport =
I have an sql query that counts the number of results for a complex
So, I've got a query that looks something like this: SELECT id, DATE_FORMAT(CONVERT_TZ(callTime,'+0:00','-7:00'),'%b %d
The following line is giving an error message. $query = 'SELECT * FROM products

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.