mysql - Select a field from sql IF, otherwise select another -
i have 3 fields in table designated structure relations between ids. means, example, 1 of 3 fields first_id, other 1 second_id , third 1 the_third_one. each combination of the_third_one , first_id , second_id "unique".
what want pick first_id if other_id equal second_id, or pick second_id if other_id equal first_id.
so basically, table structure this
first_id second_id the_third_one
2323 242 idrelatedstring
239 231 anotherone
and on.
my other_id 2323. want retrieve second_id , the_third_one.
my other_id 231. want retrieve first_id , the_third_one.
how should proceed query database?
try case when then
example:
select third_id, case when other_id = second_id first_id when other_id = first_id second_id end id my_table ....
Comments
Post a Comment