MySQL Forums
Forum List  »  Newbie

distinct row
Posted by: Paul Gessos
Date: March 26, 2006 12:28PM

I have table A:
============================
lang | id | sentence
--------------------
'de' | 1 | 'german word 1'
'de' | 2 | 'german word 2'
'en' | 1 | 'english word 1'
'en' | 2 | 'english word 2'
'en' | 3 | 'english word 3'
============================

I want with a query return
============================
lang | id | sentence
--------------------
'de' | 1 | 'german word 1'
'de' | 2 | 'german word 2'
'en' | 3 | 'english word 3'
============================

The meaning: For each id, if german sentence exists, return it, else return english, BUT NOT BOTH.

So, return DISTINCT but ONLY for id.
The query, until now:

SELECT * FROM A WHERE lang='en' OR lang='de' ORDER BY IF(lang='en',1,0);

Can you fix it please?
thanks

Options: ReplyQuote


Subject
Written By
Posted
distinct row
March 26, 2006 12:28PM
March 26, 2006 12:48PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.