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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:45:32+00:00 2026-05-21T08:45:32+00:00

Basically, there is an attribute table and translation table – many translations for one

  • 0

Basically, there is an attribute table and translation table – many translations for one attribute.

I need to select id and value from translation for each attribute in a specified language, even if there is no translation record in that language. Either I am missing some join technique or join (without involving language table) is not working here since the following do not return attributes with non-existing translations in the specified language.

select a.attribute, at.id, at.translation 
from attribute a left join attributeTranslation at on a.id=at.attribute
where al.language=1;

So I am using subqueries like this, problem here is making two subqueries to the same table with the same parameters (feels like performance drain unless MySQL groups those, which I doubt since it makes you do many similar subqueries)

select attribute, 
(select id from attributeTranslation where attribute=a.id and language=1),
(select translation from attributeTranslation where attribute=a.id and language=1), 
from attribute a;

I would like to be able to get id and translation from one query, so I concat columns and get the id from string later, which is at least making single subquery but still not looking right.

select attribute,
(select concat(id,';',title)
    from offerAttribute_language 
    where offerAttribute=a.id and _language=1
)
from offerAttribute a

So the question part.
Is there a way to get multiple columns from a single subquery or should I use two subqueries (MySQL is smart enough to group them?) or is joining the following way to go:

[[attribute to language] to translation] (joining 3 tables seems like a worse performance than subquery).

  • 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-21T08:45:33+00:00Added an answer on May 21, 2026 at 8:45 am

    Yes, you can do this. The knack you need is the concept that there are two ways of getting tables out of the table server. One way is ..

    FROM TABLE A
    

    The other way is

    FROM (SELECT col as name1, col2 as name2 FROM ...) B
    

    Notice that the select clause and the parentheses around it are a table, a virtual table.

    So, using your second code example (I am guessing at the columns you are hoping to retrieve here):

    SELECT a.attr, b.id, b.trans, b.lang
    FROM attribute a
    JOIN (
     SELECT at.id AS id, at.translation AS trans, at.language AS lang, a.attribute
     FROM attributeTranslation at
    ) b ON (a.id = b.attribute AND b.lang = 1)
    

    Notice that your real table attribute is the first table in this join, and that this virtual table I’ve called b is the second table.

    This technique comes in especially handy when the virtual table is a summary table of some kind. e.g.

    SELECT a.attr, b.id, b.trans, b.lang, c.langcount
    FROM attribute a
    JOIN (
     SELECT at.id AS id, at.translation AS trans, at.language AS lang, at.attribute
     FROM attributeTranslation at
    ) b ON (a.id = b.attribute AND b.lang = 1)
    JOIN (
     SELECT count(*) AS langcount,  at.attribute
     FROM attributeTranslation at
     GROUP BY at.attribute
    ) c ON (a.id = c.attribute)
    

    See how that goes? You’ve generated a virtual table c containing two columns, joined it to the other two, used one of the columns for the ON clause, and returned the other as a column in your result set.

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

Sidebar

Related Questions

Is there any name for the following DB table design: Basically we have generic
I basically need to check if there is an easier way to do this
Is there an easy way to create standalone .exe files from Lua scripts? Basically
Is there a way to emulate mixins or traits in java? basically, I need
I basically have a table with headers that I read in from a DB
I just want to design this very simple website. Basically there are multiple pages
I have some localization problems in my webpage. There are basically two problems (that
I like to generate a thread dump programmatically. I've learned that there a basically
Are there any more generic tools that can compile or basically merge multiple PHP
Is there any simple way to programatically colorize images in .NET? Basically we 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.