I need to make a Select in 3 different tables and do not know how to do

Asked

Viewed 83 times

-1

Next I need to make a query in the following conditions:

  • I need the table data A (Numero, Ano, vencimento, Nome);

  • seeking the information of unwelcome in the column Recebimento table B;

  • and I need the column Numero table A are not on the table C

I did something like that, but it didn’t happen

SELECT * 
FROM Table A
WHERE a.NUMERO > 100 
AND a.ANO BETWEEN '01-JAN-2019' AND '01-JAN-2021' A.VENCIMENTO 
AND A.NOME 
AND b.RECEBIMENTO IS NULL IN (SELECT TABLE b) 
AND a.NUMERO IS NOT  IN (SELECT c.NUMERO 
                         FROM  TABLE C 
                         WHERE c.ANO = a.ANO) 
  • This "AND b.RECEIPT IS NULL IN (SELECT TABLE b) ", the "b. RECEIVING" will not find table B as it is not related in the main select may have been a typo

  • What is the database? You can add the sql question of the tables?

1 answer

1

The consultation presents some inconsistencies to be remedied:

  1. FROM Table A must be FROM A
  2. AND a.ANO BETWEEN '01-JAN-2019' AND '01-JAN-2021' A.VENCIMENTO can be and A.VENCIMENTO BETWEEN '01-01-2019' AND '01-03-2021'
  3. note that I changed 'JAN' for '01'.
  4. A.VENCIMENTO came to before the BETWEEN
  5. AND A.NOME isolated does not make sense, because it needs to be an expression that checks something.

Here is a query that can be used.

select a.* 
  from a left join b on a.numero = b.numero 
where a.NUMERO > 100 
  and A.VENCIMENTO BETWEEN '01-01-2019' AND '01-03-2021'
  and b.recebimento is null
  and not exists (select * from c where c.numero = a.numero and c.ano = a.ano)
  • First the union between the tables was performed a and b.
  • Since the tables have been attached, we use the clause where the stretch and b.recebimento is null to exclude from results tuples that do not meet this requirement.
  • Then we verify the non-existence of the table data c in relation to table a to satisfy that other requirement.

Browser other questions tagged

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