Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Left join question

Author  Topic 

contec
Starting Member

9 Posts

Posted - 2007-01-04 : 15:11:56
Hi,

I'm trying to figure out some confusion regarding left joins.

I have table A, which I want to join to tables B and C.

SELECT COUNT(*) FROM A

and

SELECT COUNT(*) FROM A LEFT JOIN B ON A.ID = B.ID LEFT JOIN C ON A.ID = C.ID

return different results. How can I make the join return ONLY the number of rows in table A?

I want A to be the parent table and I want no duplication of rows, as I'm using the result of the join as a fact table for a cube, so when there are duplicated rows in table A the totals for A's columns are wrong.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-04 : 16:38:59
SELECT COUNT (DISTINCT TableA.<YourColumnNameHere>)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -