Neste sexto tópico falarei sobre junções, ou JOINs. JOIN é uma técnica para visualizar dados de multiplas tabelas através de um único SELECT. Existem diversos tipos de JOINs, que podem ser vistos a seguir:

  • INNER JOINS
  1.    NATURAL JOIN
  2.    JOIN … USING
  3.    JOIN … ON
  4.    CARTESIAN JOINS (CROSS JOIN)
  • OUTER JOINS
  1.    LEFT OUTER JOIN
  2.    RIGHT OUTER JOIN
  3.    FULL OUTER JOIN
  • SELF-JOIN

É importante mencionar que todos os exemplos abaixo foram feitos usando a sintaxe ANSI SQL, que serve para todos os bancos que implementam esse padrão de SQL, ou seja, todos. Esse também é o tipo de sintaxe abordada nas provas 11g do Oracle.

1) INNER JOINS

Também pode ser chamado de EQUI JOIN. Esse tipo de JOIN uma um operador de igualdade para comparar linhas de multiplas tabelas. Caso essas linhas “batam” estas serão retornadas pelo SELECT. Mais adiante é possível ver os tipos de INNER JOIN:

1.1) NATURAL JOIN

O join é baseado em todas as colunas com os mesmos nomes em todas as tabelas.envolvidas no SELECT. Ex:

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”IC0tIGFzIDIgdGFiZWxhcyBhYmFpeG8gcG9zc3VlbSBhIGNvbHVuYSBlbSBjb211bSBJRF9ERVBBUlRBTUVOVE8KCiBTRUxFQ1QgSURfRU1QLCAKIE5PTUVfRU1QLCAKIE5PTUVfREVQQVJUQU1FTlRPIAogRlJPTSBDRVJUSUZJQ0FDQU8uVEFCX0VNUFJFR0FET1MgTkFUVVJBTCBKT0lOIAogICAgICBDRVJUSUZJQ0FDQU8uVEFCX0RFUEFSVEFNRU5UT1MKCiAtLSBjb2x1bmFzIGVtIGNvbXVtIG7Do28gcG9kZW0gdGVyIHF1YWxpZmljYWRvcmVzLiAKIC0tIG8gZXhlbXBsbyBhYmFpeG8gZ2VyYSBvIGVycm8gIm9yYS0yNTE1NTogY29sdW1uIHVzZWQgaW4gCiAtLSBOQVRVUkFMIGpvaW4gY2Fubm90IGhhdmUgcXVhbGlmaWVyIgoKIFNFTE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X0VNUCwgCiBFLk5PTUVfRU1QLCAKIEUuSURfREVQQVJUQU1FTlRPLAogRC5OT01FX0RFUEFSVEFNRU5UTyAKIEZST00gQ0VSVElGSUNBQ0FPLlRBQl9FTVBSRUdBRE9TIEUgTkFUVVJBTCBKT0lOIAogICAgICBDRVJUSUZJQ0FDQU8uVEFCX0RFUEFSVEFNRU5UT1MgRAoKIC0tIHBhcmEgY29sdW5hcyBjb211bnMgZW0gdG9kYXMgYXMgdGFiZWxhcywgYmFzdGEgb21pdGlyIAogLS0gbyBxdWFsaWZpY2Fkb3IKCiBTRUxFQ1QgRS5JRF9FTVAsIAogRS5OT01FX0VNUCwgCiBJRF9ERVBBUlRBTUVOVE8sIC0tY29sdW5hIGNvbXVtCiBELk5PTUVfREVQQVJUQU1FTlRPIAogRlJPTSBDRVJUSUZJQ0FDQU8uVEFCX0VNUFJFR0FET1MgRSBOQVRVUkFMIEpPSU4gCiAgICAgIENFUlRJRklDQUNBTy5UQUJfREVQQVJUQU1FTlRPUyBE[/et_pb_dmb_code_snippet]

1.2) JOIN … USING

Especifica através da clausula USING, colunas com nomes comuns nas tabelas a serem usadas nos JOINS. Ex:

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”LS0gbmEgY2xhdXN1bGEgdXNpbmcgZGV2ZSBzZXIgZXNwZWNpZmljYWRhIGEgY29sdW5hIGNvbXVtIAotLSDDoHMgdGFiZWxhcwoKIFNFTEVDVCBFLklEX0VNUCwgCiBFLk5PTUVfRU1QLCAKIEQuTk9NRV9ERVBBUlRBTUVOVE8gCiBGUk9NIENFUlRJRklDQUNBTy5UQUJfRU1QUkVHQURPUyBFIEpPSU4gCiAgICAgIENFUlRJRklDQUNBTy5UQUJfREVQQVJUQU1FTlRPUyBEIAogICAgICBVU0lORyAoSURfREVQQVJUQU1FTlRPKQoKIC0tIGNvbHVuYXMgZW0gY29tdW0gbsOjbyBwb2RlbSB0ZXIgcXVhbGlmaWNhZG9yZXMuIAogLS0gbyBleGVtcGx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gZW0gY29tdW0gbsOjbyBwb2RlbSB0ZXIgcXVhbGlmaWNhZG9yZXMuIAogLS0gbyBleGVtcGxvIGFiYWl4byBnZXJhIG8gZXJybyAib3JhLTI1MTU0OiBjb2x1bW4gdXNlZCBpbiAKIC0tIFVTSU5HIGpvaW4gY2Fubm90IGhhdmUgcXVhbGlmaWVyIgoKIFNFTEVDVCBFLklEX0VNUCwgCiBFLk5PTUVfRU1QLCAKIEUuSURfREVQQVJUQU1FTlRPLAogRC5OT01FX0RFUEFSVEFNRU5UTyAKIEZST00gQ0VSVElGSUNBQ0FPLlRBQl9FTVBSRUdBRE9TIEUgSk9JTiAKICAgICAgQ0VSVElGSUNBQ0FPLlRBQl9ERVBBUlRBTUVOVE9TIEQgCiAgICAgIFVTSU5HIChJRF9ERVBBUlRBTUVOVE8pCgogLS0gcGFyYSBjb2x1bmFzIGNvbXVucyBlbSB0b2RhcyBhcyB0YWJlbGFzLCBiYXN0YSBvbWl0aXIgbyAKIC0tIHF1YWxpZmljYWRvcgoKIFNFTEVDVCBFLklEX0VNUCwgCiBFLk5PTUVfRU1QLCAKIElEX0RFUEFSVEFNRU5UTywKIEQuTk9NRV9ERVBBUlRBTUVOVE8gCiBGUk9NIENFUlRJRklDQUNBTy5UQUJfRU1QUkVHQURPUyBFIEpPSU4gCiAgICAgIENFUlRJRklDQUNBTy5UQUJfREVQQVJUQU1FTlRPUyBEIAogICAgICBVU0lORyAoSURfREVQQVJUQU1FTlRPKQ==[/et_pb_dmb_code_snippet]

1.3) JOIN … ON

Define especificamente as condições e colunas que farão o JOIN. Ex:

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”LS0gZGVmaW5lIHF1ZSBvIGpvaW4gc2VyYSBmZWl0byBwZWxhcyBjb2x1bmFzIGlkX2RlcGFydGFtZW50byAKLS0gZGUgYW1iYXMgYXMgdGFiZWxhcywgb3Ugc2VqYSxzbyByZXRvcm5hcmEgcmVzdWx0YWRvcyBjYXNvIGFzIAotLSBkdWFzI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0VSVElGSUNBQ0FPLlRBQl9FTVBSRUdBRE9TIEUgSk9JTiAKICAgICAgQ0VSVElGSUNBQ0FPLlRBQl9ERVBBUlRBTUVOVE9TIEQgCiAgICAgIE9OIChFLklEX0RFUEFSVEFNRU5UTyA9IEQuSURfREVQQVJUQU1FTlRPKQoKIC0tIMOpIHBvc3PDrXZlbCBlc3BlY2lmaWNhciBtYWlzIGRlIHVtYSBjb2x1bmEgCgogU0VMRUNUIEUuSURfRU1QLCAKIEUuTk9NRV9FTVAsIAogRS5JRF9ERVBBUlRBTUVOVE8sCiBELk5PTUVfREVQQVJUQU1FTlRPIAogRlJPTSBDRVJUSUZJQ0FDQU8uVEFCX0VNUFJFR0FET1MgRSBKT0lOIAogICAgICBDRVJUSUZJQ0FDQU8uVEFCX0RFUEFSVEFNRU5UT1MgRCAKICAgICAgT04gKEUuSURfREVQQVJUQU1FTlRPID0gRC5JRF9ERVBBUlRBTUVOVE8gCiAgICAgICAgIEFORCBFLklEX0VNUCA9IEQuSURfR0VSRU5URSk=[/et_pb_dmb_code_snippet]

1.4) CARTESIAN JOINS (CROSS JOIN)

Ocorrem quando os dados são selecionados de 2 ou mais tabelas, mas nenhuma condição é especificada. Cada linha da 1º tabela é unida com cada linha da 2º tabela. Se a tabela A possui 3 linhas e a tabela B possui 4 linhas, o select resultante retorna 12 (3 x 4) linhas. Ex:

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”LS0gdW5lIGNhZGEgbGluaGFzIGRlIFRBQl9FTVBSRUdBRE9TIGNvbSBjYWRhIGxpbmhhIGRlIAotLSBUQUJfREVQQVJUQU1FTlRPUwotLSBldml0ZSBmYXplciBpc3NvLiBhbMOpbSBkZSBuw6NvIHJldG9ybmFyIGluZm9ybWHDp8O1ZXMgw7p0ZWlzLCAKLS0gZGVwZW5kZW5kbyBkbyB0YW1hbmhvIGRhcyB0YWJlbGFzLCBpc3NvIHBvZGUgb2N1cGFyIHRvZGEgYSBhcmVhIC0tIGRlIG1lbcOzcmlhIGRpc3BvbsOtdmVsIHBhcmEgaXNzby4KIFNFTEVDVCAqCiBGUk9NIENFUlRJRklDQUNBTy5UQUJfRU1QUkVHQURPUyBFLCAKICAgICAgQ0VSVElGSUNBQ0FPLlRBQl9ERVBBUlRBTUVOVE9TIEQ=” hover_enabled=”0″]LS0gdW5lIGNhZGEgbGluaGFzIGRlIFRBQl9FTVBSRUdBRE9TIGNvbSBjYWRhIGxpbmhhIGRlIAotLSBUQUJfREVQQVJUQU1FTlRPUwotLSBldml0ZSBmYXplciBpc3NvLiBhbMOpbSBkZSBuw6NvIHJldG9ybmFyIGluZm9ybWHDp8O1ZXMgw7p0ZWlzLCAKLS0gZGVwZW5kZW5kbyBkbyB0YW1hbmhvIGRhcyB0YWJlbGFzLCBpc3NvIHBvZGUgb2N1cGFyIHRvZGEgYSBhcmVhIC0tIGRlIG1lbcOzcmlhIGRpc3BvbsOtdmVsIHBhcmEgaXNzby4KIFNFTEVDVCAqCiBGUk9NIENFUlRJRklDQUNBTy5UQUJfRU1QUkVHQURPUyBFLCAKICAgICAgQ0VSVElGSUNBQ0FPLlRBQl9ERVBBUlRBTUVOVE9TIEQ=[/et_pb_dmb_code_snippet]

2) OUTER JOINS

Retorna linhas que são encontradas em todas as tabelas, bem como linhas que não foram encontradas em alguma das tabelas envolvidas no SELECT.

2.1) LEFT OUTER JOIN

Citando o documento da própria Oracle para explicar esse conceito:

“A LEFT OUTER JOIN is one of the JOIN operations that allow you to specify a join clause. It preserves the unmatched rows from the first (left) table, joining them with a NULL row in the shape of the second (right) table.”

A dica que eu passo a vocês, para facilitar é: LEFT OUTER JOIN deve ser usado quando eu precisar de TUDO que estiver apenas na tabela a esquerda, não importando se existam registros equivalentes na tabela da direita

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”IC0tIHJldG9ybmEgb3MgcmVnaXN0cm9zIHF1ZSBwb3NzdWVtIG8gaWRfZGVwYXJ0YW1lbnRvIGNvbXVtIAogLS0gZW0gYW1iYXMgY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AogRS5JRF9ERVBBUlRBTUVOVE8sCiBELk5PTUVfREVQQVJUQU1FTlRPIAogRlJPTSBDRVJUSUZJQ0FDQU8uVEFCX0RFUEFSVEFNRU5UT1MgRCBMRUZUIE9VVEVSIEpPSU4gCiAgICAgIENFUlRJRklDQUNBTy5UQUJfRU1QUkVHQURPUyBFCiAgICAgIE9OIChFLklEX0RFUEFSVEFNRU5UTyA9IEQuSURfREVQQVJUQU1FTlRPKQ==[/et_pb_dmb_code_snippet]

OBS1: A cláusula OUTER é opcional

2.2) RIGHT OUTER JOIN

Citando o documento da própria Oracle para explicar esse conceito:

“A RIGHT OUTER JOIN is one of the JOIN operations that allow you to specify a JOIN clause. It preserves the unmatched rows from the second (right) table, joining them with a NULL in the shape of the first (left) table. A LEFT OUTER JOIN B is equivalent to B RIGHT OUTER JOIN A, with the columns in a different order.”

A dica que eu passo a vocês, para facilitar é: RIGHT OUTER JOIN deve ser usado quando eu precisar de TUDO que estiver apenas na tabela a direita, não importando se existam registros equivalentes na tabela da esquerda

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”IC0tIHJldG9ybmEgb3MgcmVnaXN0cm9zIHF1ZSBwb3NzdWVtIG8gaWRfZGVwYXJ0YW1lbnRvIGNvbXVtIAogLS0gZW0gYW1iYXMgYXMgdGFiZWxhcywgYmVtIGNvbW8gb3MgZW1wcmVnYWRvcyBxdWUgbsOjbyBwb3NzdWVtIAogLS0gZGVwYXJ0YW1lbnRvcyBhc3NvY2lhZG9zLgogLS0gcmV0b3JuYSBkYWRvcyBkYSB0YWJlbGEgYSBkaXJlaXRhIG5hIGNsYXVzdWxhIGZyb20sIG1lc21vIAogLS0gcXVlIGVzc2VzIGRhZG9zIG7Do28gcG9zc3VhbSBjb3JyZXNwb25kZW50ZXMgbmEgdGFiZWxhIAogLS0gZGEgZXNxdWVyCgogU0VMRUNUIEUuSURfRU1QLCAKIEUuTk9NRV9FTVAsIAogRS5JRF9ERVBBUlRBTUVOVE8sCiBELk5PTUVfREVQQVJUQU1FTlRPIAogRlJPTSBDRVJUSUZJQ0FDQU8uVEFCX0RFUEFSVEFNRU5UT1MgRCBSSUdIVCBPVVRFUiBKT0lOIENFUlRJRklDQUNBTy5UQUJfRU1QUkVHQURPUyBFCiBPTiAoRS5JRF9ERVBBUlRBTUVOVE8gPSBELklEX0RFUEFSVEFNRU5UTyk=” hover_enabled=”0″]IC0tIHJldG9ybmEgb3MgcmVnaXN0cm9zIHF1ZSBwb3NzdWVtIG8gaWRfZGVwYXJ0YW1lbnRvIGNvbXVtIAogLS0gZW0gYW1iYXMgYXMgdGFiZWxhcywgYmVtIGNvbW8gb3MgZW1wcmVnYWRvcyBxdWUgbsOjbyBwb3NzdWVtIAogLS0gZGVwYXJ0YW1lbnRvcyBhc3NvY2lhZG9zLgogLS0gcmV0b3JuYSBkYWRvcyBkYSB0YWJlbGEgYSBkaXJlaXRhIG5hIGNsYXVzdWxhIGZyb20sIG1lc21vIAogLS0gcXVlIGVzc2VzIGRhZG9zIG7Do28gcG9zc3VhbSBjb3JyZXNwb25kZW50ZXMgbmEgdGFiZWxhIAogLS0gZGEgZXNxdWVyCgogU0VMRUNUIEUuSURfRU1QLCAKIEUuTk9NRV9FTVAsIAogRS5JRF9ERVBBUlRBTUVOVE8sCiBELk5PTUVfREVQQVJUQU1FTlRPIAogRlJPTSBDRVJUSUZJQ0FDQU8uVEFCX0RFUEFSVEFNRU5UT1MgRCBSSUdIVCBPVVRFUiBKT0lOIENFUlRJRklDQUNBTy5UQUJfRU1QUkVHQURPUyBFCiBPTiAoRS5JRF9ERVBBUlRBTUVOVE8gPSBELklEX0RFUEFSVEFNRU5UTyk=[/et_pb_dmb_code_snippet]

OBS1: A cláusula OUTER é opcional

3) SELF-JOIN

Realiza um JOIN entre uma tabela e “ela mesma”. O nome da tabela aparece na clausula FROM, duas vezes, com aliases diferentes. Ex:

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”LS0gbW9zdHJhIG9zIGdlcmVudGVzIGRlIGNhZGEgZW1wcmVnYWRvLiBjYWRhIGdlcmVudGUgdGFtYsOpbSDDqSAKLS0gdW0gZW1wcmVnYWRvLgoKIFNFTEVDVCBUQS5OT01FX0VNUCB8fCAnIHRyYWJhbGhhIHBhcmEgJyB8fCBUQi5OT01FX0VNUCAKIEZST00gQ0VSVElGSUNBQ0FPLlRBQl9FTVBSRUdBRE9TIFRBIEpPSU4gCiAgICAgIENFUlRJRklDQUNBTy5UQUJfRU1QUkVHQURPUyBUQiAKICAgICAgT04gKFRBLklEX0dFUkVOVEUgPSBUQi5JRF9FTVAp” hover_enabled=”0″]LS0gbW9zdHJhIG9zIGdlcmVudGVzIGRlIGNhZGEgZW1wcmVnYWRvLiBjYWRhIGdlcmVudGUgdGFtYsOpbSDDqSAKLS0gdW0gZW1wcmVnYWRvLgoKIFNFTEVDVCBUQS5OT01FX0VNUCB8fCAnIHRyYWJhbGhhIHBhcmEgJyB8fCBUQi5OT01FX0VNUCAKIEZST00gQ0VSVElGSUNBQ0FPLlRBQl9FTVBSRUdBRE9TIFRBIEpPSU4gCiAgICAgIENFUlRJRklDQUNBTy5UQUJfRU1QUkVHQURPUyBUQiAKICAgICAgT04gKFRBLklEX0dFUkVOVEUgPSBUQi5JRF9FTVAp[/et_pb_dmb_code_snippet]

É isso ai pessoal. Por hoje já deu. Até a próxima oportunidade. Keep Querying.