Thursday, April 19, 2012

query with grouped results by collum

I've got a many to many relationship between items-itemnames-languages

the itemnames don't appear for every language.

I'd like to get a result with all the items only represented once, but be able to set the languageId to default to.

for example items 1,2,3 are defined in two languages, and item 4 and 5 have one language each, but the languages are different

1, 1, item1
1, 2, leItem1
2, 1, item2
2, 2, leItem2
3, 1, item3
3, 2, leItem3
4, 1, item4
5, 2, leItem5

I'd like to create a query that only gives me one of each itemID, but allow me to specify which language to prefer, so if I select a languageID of 2, my query would only return item names for that start with 'leItem' with the exception of item 4, which should still give me item4

Any ideas how to achieve this with a SELECT?

No comments:

Post a Comment