Home > Mobile >  Trying to join these 3 tables but nothing shows up
Trying to join these 3 tables but nothing shows up

Time:02-04

Have to link 3 tables together, all 3 have matching column modified date, however when I run the query in Microsoft SQL Server, it executes, the columns show up however there is no data in the joined tables... is there a problem with my syntax?

select 
    sod.SalesOrderID, sod.ProductID, sod.UnitPrice, sod.LineTotal, 
    sod.ModifiedDate, p.ProductCategoryID, sp.SalesYTD,
    sp.SalesLastYear, sp.SalesQuota
from 
    AdventureWorks2019.Sales.SalesOrderDetail sod
join 
    AdventureWorks2019.Production.ProductCategory p on sod.ModifiedDate = p.ModifiedDate 
join 
    AdventureWorks2019.Sales.SalesPerson sp on sod.ModifiedDate = sp.ModifiedDate;

CodePudding user response:

without knowing any more details, check which type of JOIN you actually want to use.

  • JOIN: returns records that have matching values in both tables

  • LEFT OUTER JOIN: returns all records from the left table, and the matched records from the right table

  • RIGHT OUTER JOIN: returns all records from the right table, and the matched records from the left table

More details at: https://www.w3schools.com/sql/sql_join.asp

  •  Tags:  
  • Related