mysql - Selecting last version of entry in different language from sql database -
is there way in 1 sql query? newest (version) of same entry in every language available.
my table , example data is:
id | index | version | language | ... ------------------------------------------------ 1 1 1 1 test1 2 1 2 1 test2 3 2 1 1 test3 4 2 1 2 test4 5 2 1 3 test5 6 2 2 3 test6 7 3 1 1 test7 8 3 1 2 test8
- id unique identifer
- index unique entry in database means time versions , language version of same article/entry share same index.
- version version number. 1 first version , greater number newer.
- language number of language version of entry/article.
i can't think of way in 1 query. maybe it's feasible?
i this:
id | index | version | language | ... ------------------------------------------------ 2 1 2 1 test2 3 2 1 1 test3 4 2 1 2 test4 6 2 2 3 test6 7 3 1 1 test7 8 3 1 2 test8
test1 out because test2 in same language , it's newer
test5 out because test6 newer in same language
resolved
select t1.* entry_view t1 left join entry_view t2 on (t1.version < t2.version , t1.id_language = t2.id_language , t1.`index` = t2.`index`) t2.id null
select t1.id, t1.index, t1.version, t1.language table t1 left join table t2 on (t1.id < t2.id , t1.language = t2.language) t2.id null
edit: assumed ids increasing , newest 1 last.
maybe try this:
select t1.id, t1.index, t1.version, t1.language table t1 left join table t2 on (t1.version < t2.version , t1.language = t2.language) t2.id null
Comments
Post a Comment