Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

Tampilan SQL:Bergabung dengan tabel tanpa menyebabkan data terduplikasi di setiap baris?

Anda harus menggunakan UNION (sebenarnya UNION ALL) dalam kasus ini.

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. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Sembunyikan database SQL dari Management Studio

  2. PHP 5.5.0 dengan Microsoft SQL Server 2008 R2 - Tidak ada sqlsrv_connect()?

  3. Cara membuat kueri dengan group_concat di sql server

  4. Bagaimana cara mengubah data ke format json di SQL Server 2008?

  5. Kesalahan SQL Server 111:"... harus menjadi pernyataan pertama dalam kumpulan kueri"