SQL Query according to the Make a New Column

Asked

Viewed 56 times

0

I have a column that is numerical. In this column there are positive and negative values. I need to make an appointment that when I’m positive, I’ll consult Tabela A, when negative I refer to Tabela B. I have no idea how to do that?

  • both in the past and in the java you can make a if to validate.

  • I consulted and used LEFT JOIN and then use an if to check the value of the column and get the value that interests me, vlw

  • Vote today! Vote tomorrow! Vote forever! Vote consciously! Your vote is very important to our community, contribute to us, and help make Stack Overflow in Portuguese (Sopt) bigger and bigger. You can learn more at: Vote early, vote often

1 answer

0

A possible solution is :

Create a view that brings the two together

tables

create or replace view v_view as
select cod,nome
from tabela1
union 
select cod,nome
from tabela2

Do the Join in the view

select *
from tabela3,v_view
where v_view.cod = tabela3.cod 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.