sql >> Databasteknik >  >> RDS >> Sqlserver

SQL-vy:Sammanfoga tabeller utan att få data att dupliceras på varje rad?

Du skulle behöva använda en UNION (faktiskt UNION ALL) i det här fallet.

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. Förvandla en parameter med flera värden till en tillfällig tabell i SQL Server Business Intelligence Development Studio

  2. Bindestreck vs bindestreck :Byt ut bindestreck med bindestreck

  3. Behöver trimma tomt utrymme i oracle

  4. Analysera I/O-prestanda för SQL Server