Question

I have a query that has a list of base values and a list of language values. Each value has a key that matches to the other. The base values are stored in one table and the language values in another. My problem is that I need to get all matching base values removed from the QUERY except for one. Then, I export that query into an Excel spreadsheet (I can do this portion fine) and allow the user to edit the language values.

When the user edits and/or inserts new language values, I need to update the database except now writing over any matching values in the database (like those that were removed the first time).

In simplicity, the client pays for translations and if I can generate a sheet that has fewer translations needed (like phrases that reappear often) then they can save money, hence the project to begin with. I realize the downside is that it is not a true linked list, where all matching values all belong to one row in the language table (which would have been easy). Instead, there are multiple values that are identical that need to be updated as described above.


Yeah, I'm confused on it which is why it might seem a little vague. Here's a sample:

Table 1
Item Description1
Item Description2
Item Description3
Item Description2
Item Description2
Item Description4
Item Description5
Item Description6
Item Description3

Table 2
Item Desc in other Language1
Item Desc in other Language2
Item Desc in other Language3  (blank)
Item Desc in other Language3
Item Desc in other Language4
Item Desc in other Language5
*blank*

Desired Result (when queried)

Table 1 Item Description1 Item Description2 Item Description3 Item Description4 Item Description5 Item Description6

Table 2
Item Desc in other Language1
Item Desc in other Language2
Item Desc in other Language3 (filled by matching row in Table 2)
Item Desc in other Language4
Item Desc in other Language5
Item Desc in other Language6 (blank, returned as empty string)

The user makes their modifications, including inserting data into blank rows (like row 6 for the language) then reuploads:

Table 1
Item Description1
Item Description2
Item Description3
Item Description2
Item Description2
Item Description4
Item Description5
Item Description6
Item Description3

Table 2
Item Desc in other Language1
Item Desc in other Language2
Item Desc in other Language3  (now matches row below)
Item Desc in other Language3
Item Desc in other Language4
Item Desc in other Language5
Item Desc in other Language6  (new value entered by user)

There is also a resource key that matches each "Item Description" to a single "Item Desc in other Language". The only time they are ever going to see each other is during this translation process, all other times the values may be different, so the resource keys can't simply be changed to all point at one translation permanently.

I should also add, there should be no alteration of the structure of the tables or removing rows of the table.


Ok, here's an updated revisal of what I would LIKE the query to do, but obviously does not do since I actually need the values of the joined table:

SELECT pe.prodtree_element_name_l, rs.resource_value, pe.prodtree_element_name_l_rk   
FROM prodtree_element pe
        LEFT JOIN resource_shortstrings rs
            ON pe.prodtree_element_name_l_rk = rs.resource_key
        WHERE rs.language_id = '5'
            AND pe.prodtree_element_name_l <> ''
        GROUP BY pe.prodtree_element_name_l
Was it helpful?

Solution 3

Hey thanks for that update!

Looking at that and adding it into a previous post I finally came up with this:

<cfquery name="getRows" datasource="XXXX">
    SELECT pe.prodtree_element_name_l, MAX(rs.resource_value) AS resource_value
    FROM prodtree_element pe
    LEFT JOIN resource_shortstrings rs
        ON pe.prodtree_element_name_l_rk = rs.resource_key
    WHERE rs.language_id = '5'
        AND pe.prodtree_element_name_l <> ''
    GROUP BY prodtree_element_name_l
</cfquery>

I realized I didn't need a specific resource_value, just any that was in there. I also realized I didn't need the resource key at all outside of the query. The update will be updating ALL the matching base values regardless, so I didn't really need the resource key after all, which allowed me to use the GROUP BY.

Took a while, sorry for the poor explanation, but this is it! :) Thanks for all the help.

OTHER TIPS

Hrm, still not real clear on what the issue truly is, but let me give it a go.

Tables:

BASE_VALUES
------------------
BASE_VALUE_RK
BASE_VALUE_NAME

RESOURCE_VALUES (these are the translations, I'm guessing)
-----------------------
RESOURCE_KEY
RESOURCE_LANGUAGE_ID
RESOURCE_VALUE

You want to retrieve one base value, and all corresponding translation values that match that base value, export them to excel, and then re-load them via an update (I think).

SQL to SELECT out data:

SELECT bv.BASE_VALUE_RK, rv.RESOURVE_VALUE
  FROM BASE_VALUE bv, RESOURCE_VALUE rv
 WHERE bv.BASE_VALUE_RK = rv.RESOURCE_KEY
   AND rv.resource_language_id = '5'
 ORDER BY 1;

That'll give you:

1234    Foo
1235    Bar
1236    Baz

Export that to excel, and get it back with updates:

1234    Goo
1235    Car
1236    Spaz

You can then say:

UPDATE RESOURCE_VALUES
   SET RESOURCE_VALUE = value_from_spreadsheet
 WHERE RESOURCE_KEY = key_from_spreadsheet

I may be way off base on this guy, so let me know and, if you can provide a little more detail, I may be able to score closer to the mark.

Cheers!

If you need to remove all matches except for one, why not delete all the matching ... matches ... we need better terms ... and then insert the correct one. EG, if you need to update the matches between items 12 and 13 in the base pair table, do something like

delete from matchtable where (id1 = 12 and id2 = 13) or (id1 = 13 and id2 = 13);
insert into matchtable (id1, id2) values (12, 13);

I may be oversimplifying, but your description seems vague in places.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top