I need help writting a query. Using this schema as example:
Table: A
id 1
id 2
Table: ALocalized
A_id 1, culture 1, name 'EN translation'
A_id 1, culture 2, name 'PT translation'
A_id 2, culture 1, name 'EN translation'
This is the schema i’m using to localize information. Each record on A has at least one related record on ALocalized, but there may be some rows who don’t have a localized record for certain cultures.
In this example, i want to query A and filter the ALocalized by culture 2. If culture 2 doesn’t exist, then return any other available.
The result should be:
A_id 1, culture 2, name 'PT translation'
A_id 2, culture 1, name 'EN translation'
I’ve tried to do this joining both tables, using an sub query but i think that my problem is in where clause.
where (ALocalized.culture = @cultureparameter OR ALocalized.culture = 1 OR ALocalized.culture = 2) limit 1
When @cultureparameter is 2 returns culture 1. It isn’t respecting the order of where clauses
How should i do this? I was trying to avoid the use of loops to check each A record for an existence of ALocalized.
Thanks in advance
1 Answer