how to count and return zero

  • Not sure that i have fully understood the question, becuase it will be difficult to count that which does not exist. If you want a list of records that does not exist in a referenced table, then you could look at a left join.

    eg. In northwind to prove the customers that have not placed any orders you could:

    select c.companyname,o.orderid

    from customers c left join orders o on c.customerid = o.customerid

    where o.orderid is null

    ..Should return two rows. Hope this helps.

  • As J.O.S. was suggesting

    SELECT Sn.[id],COUNT(*) AS coun_id

    FROM Sn RIGHT JOIN SilokE ON sn.[id]=SilokE.[id]

    Where sn.[id] IS NULL

    GROUP BY SilokE.[id]

    For all remove the where clause.

Viewing 2 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply