sql >> Database teknologi >  >> RDS >> Sqlserver

SQL-visning:Forbind tabeller uden at få dataene til at duplikere på hver række?

Du skal bruge en UNION (faktisk UNION ALL) i dette tilfælde.

select a.name as account_Name, 
       p.description as property_DESCRIPTION, 
       p.address as property_ADDRESS, 
       null as vehicles_DESCRIPTION,
       null as vehicles_MAKE, 
       null as vehicles_MODEL
    from Accounts a
        inner join Properties p
            on a.accountid = p.accountid
UNION ALL   
select a.name as account_Name, 
       null as property_DESCRIPTION, 
       null as property_ADDRESS, 
       v.description as vehicles_DESCRIPTION,
       v.make as vehicles_MAKE, 
       v.model as vehicles_MODEL
    from Accounts a
        inner join vehicles v
            on a.accountid = v.accountid


  1. SQL Server tuning - det handler om måling

  2. Jeg vil have mysql-tabel til at understøtte to sprog

  3. Vælg alle felter, hvor feltværdien ikke er i matrix

  4. Stor PHP Arrays paginering