How to return NULL in LEFT JOIN?

Asked

Viewed 130 times

1

I have two tables I need to manipulate:

  • interventioniscy : idintervencaopriority , idcelula...
  • cellula : idcelula, name...

    SELECT ip.idintervencaoprioridade, zc.nome nome_celula 
    FROM intervencaoprioridade ip 
    LEFT JOIN celula zc ON ip.idcelula = zc.idcelula 
    WHERE ip.idintervencaoprioridade = 22
    

The field ip.idcelula can be NULL, but when I do this query returns the first record of the table celula. I’ve seen other examples in ONLY, but I saw nothing to help me.

  • There’s something strange here. You want to do it. left join of the entity celula and you’re wearing a zonacelula

  • fixed, and it already works, I was making a WHERE for an id that was not null. happens.

1 answer

1


This can happen to more users as in my case, I leave my answer and solution if it is useful to others.

When I auditioned for a id = 22 this one didn’t have the field idcelula to null hence he returns another value which by coincidence was the first. Taking the test more carefully I noticed that detail, and I changed the test log to one that had the idcelula to null.

Browser other questions tagged

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