LEFT JOIN com having

Asked

Viewed 97 times

-1

If I have to use a grouping that involves a field of my table that is related through LEFT JOIN and need to use HAVING, how would it look? I know that in WHERE I can not put because ignores LEFT and becomes mandatory the value.

  • Has any response helped solve the problem and can address similar questions from other users? If so, make sure to mark the answer as accepted. To do this just click on the left side of it (below the indicator of up and down votes).

2 answers

1

In case you don’t want the field of LEFT be required you can check if it is not NULL first:

...
WHERE (chave_tabela_left IS NULL OR campo_tabela_left = 'VALOR DESEJADO')
...

1

Good afternoon!! Try to pass the condition within the connection conditions, like:

SELECT * FROM tabela1 t1
  LEFT JOIN tabela2 t2
    ON t1.chave = t2.chave AND t2.chave <> 2

I hope it works!

Browser other questions tagged

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