Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. ID : Product : Description
  2. 1 : Apple : This fruit grows on trees
  3. 2 : Cherry : This fruit grows on a bush
  4.  
  5. ID : Sold
  6. 1 : 15
  7. 1 : 10
  8. 2 : 13
  9. 1 : 8
  10. 2 : 5
  11.  
  12. ID : Title : Description : Sold (Count)
  13. 1 : Apple : This fruit grows on trees : 33
  14. 2 : Cheery : This fruit grows on a bush : 18
  15.  
  16. SELECT a.ID, a.Title, a.Description, isnull(b.Sold, 0) as SellCount
  17. FROM TableA a
  18. LEFT JOIN
  19. (SELECT Count(b.Sold), b.ID From TableB b Where b.ID = a.ID Group By b.Sold) as b
  20. ON b.ID = a.ID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement