0

I have a table like this

id alias_word language  original
1    word1      es      changed_word
2    word1      en      orig_word
3    word1      fr      changed_word
4    word2      de      other_original

Supposing reference column language = es

How to make a query to have result all rows that have alias_word column = word1 and the original column is different than original column where language column = es

espected result:

2 word1 en orig_word

Ihave tried this and have empty result

SELECT * FROM words WHERE alias_word = 'word1' AND original <> original

2 Answers 2

1

Try using a self join:

SELECT w2.*
FROM words w1
INNER JOIN words w2
    ON w1.alias_word = w2.alias_word AND
       w1.original <> w2.original
WHERE
    w1.language = 'es';

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Ok. thank's ... It work. I have added WHERE w1.language = 'es' AND w1.alias = 'my_wanted_alias'; to adapt at my needs
0

AND original <> original Will always return nothing. I don't quite follow what you are doing with that original column, but I think you want to not have the word 'original' in the original column:

SELECT * 
FROM words 
WHERE alias_word = 'word1' 
    AND original <> 'original'
    AND language = 'es'

2 Comments

This works for the particular example in the OP, but does so by hard coding values.
Here something not ok ... AND original <> 'original' ... I can't know the value of original ... this must be something AND original <> 'I_need_this_value_by_one_query_where_language_es'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.