MTK
MTK

Reputation: 3570

mysql select row based in many column values

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

Upvotes: 0

Views: 49

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521409

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

Upvotes: 1

LordBaconPants
LordBaconPants

Reputation: 1414

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'

Upvotes: 0

Related Questions