How can I use something similar to an IF in an SQL query

1

I'm applying a SQL q query on Oracle SQL Developer in multiple tables where Column of a view is null in some places and then I'll need to use values of Column and not% I know how to use the query IF very well. Home Can anyone help with some possible solutions?

E.g.

SELECT x.Column1 "Alias",
       y.Column2 "Alias2",
FROM table x
INNER JOIN table y
ON (IF x.Column3 or x.Column4) = y.Column2 
.
.
.
    
asked by anonymous 03.06.2016 / 16:35

2 answers

3

A solution in Oracle

SELECT x.Column1 "Alias",
       y.Column2 "Alias2",
FROM table x,table y
ON NVL(x.Column3,x.Column4) = y.Column2 

But in general problems of this type advise a revision of the Model.

    
03.06.2016 / 17:31
1

In MySQL it can be used in the following way, as it was practically already doing:

SELECT x.Column1 "Alias",
       y.Column2 "Alias2",
FROM table x
INNER JOIN table y
ON (x.Column3 = y.Column2 OR x.Column4 = y.Column2)
    
03.06.2016 / 16:41