Is it possible to request with the substitution?

My table has columns id, inside_id and outside_id, I would like to know if I can make the query so that:

  • unless inside_id and outside_id - show id
  • if you specify id and inside_id - show inside_id
  • if you specify all three output outside_id
Of course id is always there, the other two may not be, then their value is NULL

Now I do this function with multiple queries and it need to apply :(
Thank you!
March 23rd 20 at 19:20
3 answers
March 23rd 20 at 19:22
Solution
Better case to use. Less scribbling

CASE [ expression ]
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
...
WHEN condition_n THEN result_n
ELSE result
END
depends on what they say. I specifically pointed out that the designs are different) just sign IF any, and the CASE for beginners, for example, wildness - Lawrence_Ullri commented on March 23rd 20 at 19:25
@Lawrence_Ullri, and write 10 queries :)
No, it is better to teach beginners right to the normal ways of working with the system. - Shany_Johnson57 commented on March 23rd 20 at 19:28
@Shany_Johnson57, if cope as well as case. just different syntax in General - Lawrence_Ullri commented on March 23rd 20 at 19:31
@Lawrence_Ullri, COALESCE(outside_id, inside_id, id) , and without further ADO, and you... blah-blah... - treva.Legros commented on March 23rd 20 at 19:34
@treva.Legros, but this is a good move, Yes, forgot - Lawrence_Ullri commented on March 23rd 20 at 19:37
@Lawrence_Ullri, and know whether?! and then on "Anneke" so... it has to be Easier!
want to help - help!
do not want - well, go yourself to the world %) - treva.Legros commented on March 23rd 20 at 19:40
@treva.Legros, knew and used) but for the man 1986 you're quite the show-off - Lawrence_Ullri commented on March 23rd 20 at 19:43
@Lawrence_Ullri, where did you get that?) I think it's quite the opposite! )) I'm talking with you not looking, you wanted to seem smarter than it started here in if, case to tell that it is only for your mind and the rest around all stupid, do not understand the Current in less than an hour, it became clear that you're either a show-off, or hurt, or he don't know shit... - treva.Legros commented on March 23rd 20 at 19:46
March 23rd 20 at 19:24
Solution
COALESCE(outside_id, inside_id, id)
it seems this is what you need and no superfluous words, and that Ivana is all sorts of the building itself )) thank you! - treva.Legros commented on March 23rd 20 at 19:27
March 23rd 20 at 19:26
Not gonna believe this, but MySQL has IF and other designs
don't believe me, but your attack does not make you smarter )) and me my dumb question - Yes ))))) - treva.Legros commented on March 23rd 20 at 19:29

Find more questions by tags MySQL