SQL query returning one of the empty columns, different from the database

Asked

Viewed 177 times

1

I’m doing an SQL query, in Oracle database, but one of the fields returns the empty value, different from the table in the database.

I have tried to create, and rebuild the indexes, but the problem persists.

The field itself refers to a left join that I do on the chart. When I just put the field in select, value returns, but I need more fields in select.

Example:

SELECT
A.CAMPO1,
A.CAMPO2,
B.CAMPO3 -- CAMPO RETORNANDO VAZIO

FROM TABELAA A

LEFT JOIN TABELAB B 
ON A.CAMPO1 = B.CAMPO.1
  • Hi, can you drill in better, please? What I got: Table B’s field3 is returning empty when used Left Join. If this is all, field 1 of table A is equal to field 1 of table B?

  • 1

    Raphael, try to reproduce the same data here on SQL Fiddle, if the problem persists change your question and put the fiddle link.

  • You are using LEFT JOIN. This means that if CAMPO1 exists in the TABLE but not in the TABLE then all fields in the TABLE will return NULL. That’s what you expect from LEFT JOIN.

  • Put the structure of the tables and some data to give to better understand. If it is bringing null value it is because it is null in the table, LEFT JOIN does just that...if you do not want it to bring fields that are not null use INNER JOIN it will bring records that have values in the fields you are selecting in your SELECT

1 answer

0

Good afternoon, all right?

Try to run this way:

SELECT
A.CAMPO1,
A.CAMPO2,
B.CAMPO3 -- CAMPO RETORNANDO VAZIO

FROM TABELAA A,
     TABELAB B 
WHERE   A.CAMPO1 = B.CAMPO1(+)

I had the same problem when I left SQL Server for Oracle, precisely because of how Oracle handles LEFT JOIN.

Att,

Browser other questions tagged

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