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

  • Home
  • SEARCH
  • 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 8366663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:58:13+00:00 2026-06-09T12:58:13+00:00

Please excuse the poor title – not sure how to phrase what I’m trying

  • 0

Please excuse the poor title – not sure how to phrase what I’m trying to do in a short, simple way.

I’m working on a new UI for an app with an existing DB that is localized. There can be any number of languages, and they can be created, editted or removed at any time by admins. The DB is being used by other applications, and I’m not able to modify the structure.

The DB manages a collection of artwork. There are several tables of “assets”, such as media and pieces (and others, but those 2 should suffice as examples).

Each asset table has a field called localization. This is basically a unique identifier, and is a FK to a table of the same name (localizations). for simplicity, assume the media table looks like this

id localization
1  1
2  2
3  5
4  8
5  11
...

and the pieces table uses the same localization increment, so might look like this

id localization
1  3
2  4
3  6
4  9
5  20
...

the localizations table is just a series of auto-incremented PKs.

localization
1
2
3
4
5
...

there is a localization_entries table that ties key:value pairs to a localization:

localization  language  entry_key  entry_value
1             en        title      photo of dog
1             en        detail     this is long text describing the photo of the dog.
1             es        title      foto de perro
2             en        title      photo of cat
...

Any particular localization might have an entry key and value for none, any or all of available languages.

We need to be able to search and sort using localized values. Initially, I thought the only way was to load up the dataset in it’s entirety (multiple queries), populate a PHP array of objects, then perform search and sort with PHP, but I wonder if it’s possible using straight SQL.

Ideally, I’d like to get back rows that have all localized entry values. For example, the row for the first localization would have all the fields for the media item itself, in addition to all localized values for that localization.

Something like this “works”

SELECT media.id, media.name, en.entry_value as en_title, sp.entry_value as sp_title
FROM media
JOIN localization_entries en
ON media.localization=en.localization 
JOIN localization_entries sp
ON media.localization=sp.localization
AND en.language='en' AND en.entry_key = 'title'
AND sp.language='es' AND sp.entry_key = 'title'

But obviously anything that doesn’t have an an entry_key of the appropriate key or language would not be returned (e.g., anything without an ‘es’ entry_key of ‘title’). Further, adding any kind of WHERE or ORDER BY clause fails as well…

SELECT media.id, media.name, en.entry_value AS en_title, sp.entry_value AS sp_title
FROM media
JOIN localization_entries en
ON media.localization=en.localization 
JOIN localization_entries sp
ON media.localization=sp.localization
AND en.language='en' AND en.entry_key = 'title'
AND sp.language='es' AND sp.entry_key = 'title'
WHERE en.entry_value like '%whatever%' -- would not work
ORDER BY en.entry_value

Is there a practical way to search / sort / filter using MySQL for a set of relationships like this?

TYIA

  • 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-09T12:58:14+00:00Added an answer on June 9, 2026 at 12:58 pm

    Use an outer join:

    SELECT media.id, media.name, en.entry_value as en_title, sp.entry_value as sp_title
    FROM media
    LEFT OUTER JOIN localization_entries en
    ON media.localization=en.localization AND en.language='en' AND en.entry_key = 'title'
    LEFT OUTER JOIN localization_entries sp
    ON media.localization=sp.localization AND sp.language='es' AND sp.entry_key = 'title'
    

    You’ll get NULL for en_title or sp_title if there’s no matching row in localization_entries.

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

Sidebar

Related Questions

Please excuse poor code atm, just trying to get it working before making it
Please excuse the vagueness of my title, I really don't know how to succinctly
Please excuse me, today is my first day trying to setup a CI environment
Please excuse me if I'm simple here, I want to create a simple widget
New to MVVM so please excuse my ignorance. I THINK i'm using it right
I am fairly new so firstly please excuse me if I am doing anything
Please excuse me as I'm pretty new to using .htaccess, and am having a
First time poster, so please excuse any stupidity. I'm working on porting a custom
I'm still very new to cocoa touch so please excuse any terminology that I
I'm still new top rspec, so please excuse if this is an easy one

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.