Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ID : Product : Description
- 1 : Apple : This fruit grows on trees
- 2 : Cherry : This fruit grows on a bush
- ID : Sold
- 1 : 15
- 1 : 10
- 2 : 13
- 1 : 8
- 2 : 5
- ID : Title : Description : Sold (Count)
- 1 : Apple : This fruit grows on trees : 33
- 2 : Cheery : This fruit grows on a bush : 18
- SELECT a.ID, a.Title, a.Description, isnull(b.Sold, 0) as SellCount
- FROM TableA a
- LEFT JOIN
- (SELECT Count(b.Sold), b.ID From TableB b Where b.ID = a.ID Group By b.Sold) as b
- ON b.ID = a.ID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement