Folosirea Inner Joins in SQL

Configurare noua (How To)

Situatie

Folosirea Inner Joins pentru a obtine date din mai multe tabele

Solutie

Exemplu sintaxa:

 

USE AdventureWorks2008R2;
GO
SELECT *
FROM HumanResources.Employee AS e
    INNER JOIN Person.Person AS p
    ON e.BusinessEntityID = p.BusinessEntityID
ORDER BY p.LastName

Dupa cum se vede functia INNER JOIN se foloseste pentru a concatena datele din doua tabela avand ca si criteriu de selectie conditia de egalitate dinte cele doua campuri.

O alta sintaxa ceva mai complexa poate fi ceva de forma:

USE AdventureWorks2008R2;
GO
SELECT DISTINCT p1.ProductSubcategoryID, p1.ListPrice
FROM Production.Product p1
    INNER JOIN Production.Product p2
    ON p1.ProductSubcategoryID = p2.ProductSubcategoryID
    AND p1.ListPrice <> p2.ListPrice
WHERE p1.ListPrice < $15 AND p2.ListPrice < $15
ORDER BY ProductSubcategoryID;

Dupa cum vedem conditiile pentru functia INNER JOIN pot fi foarte coplexe, rezultad tabele compuse .

Tip solutie

Permanent

Voteaza

(11 din 30 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?