Why is not a good OR in a LEFT JOIN?

3

I am creating a query and my pull request returned because the code tester considered that OR is not good for table relationships.

Example:

  FROM LEFT JOIN administracao.cidade cid
    ON (cid.cid_cd_cidade = cec.cec_cd_cidade)
    OR (cid.cid_cd_cidade = cli.cli_cd_cidade)

What would you recommend instead?

    
asked by anonymous 25.04.2018 / 15:48

2 answers

1

Using OR with LEFT JOIN , leaves query slow, an alternative is to use UNION .

  FROM LEFT JOIN administracao.cidade cid
    ON (cid.cid_cd_cidade = cec.cec_cd_cidade)
  UNION
  FROM LEFT JOIN administracao.cidade cid
    On (cid.cid_cd_cidade = cli.cli_cd_cidade)

Take a test by doing a query, and note the return time, and quote from your feedback.

    
25.04.2018 / 16:17
0

I was able to solve it now, the tester did it this way:

  FROM LEFT JOIN administracao.cidade cid_cec
    ON cid_cec.cid_cd_cidade = cec.cec_cd_cidade
  LEFT JOIN administracao.cidade cid_cli
    ON cid_cli.cid_cd_cidade = cli.cli_cd_cidade
    
25.04.2018 / 16:39