Select COUNT when using DISTINCT Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Select COUNT when using DISTINCT

  1. #1
    Join Date
    Oct 2000
    Halifax, Nova Scotia
    I am trying to get a count of rows back from the following query. When I run the query without the count I get 914 rows returned. But when I run the query using count(*) I get over 47,000 rows. Can you use DISTINCT and COUNT together in the same query.

    SELECT DISTINCT s.struct_nbr, s.struct_name, i.insp_dt,
    it.insp_type_desc, ab.approved_by_desc, ir.insp_rating_desc,
    FROM struct s, insp i, ct_insp_type it, ct_approved_by ab,
    ct_insp_rating ir, ct_struct_attr sa, insp_dtl id
    WHERE s.struct_id = i.struct_id
    AND it.insp_type_id = i.insp_type_id
    AND i.approved_by_id = ab.approved_by_id
    AND i.insp_rating_id = ir.insp_rating_id (+)
    AND s.struct_attr_id = sa.struct_attr_id
    AND i.insp_id = id.insp_id

    Don't be afraid to try something new. Amateurs built the Ark, professionals built the Titanic
    Share on Google+

  2. #2
    Join Date
    May 2002
    Yes, that is how you would get a count of distinct values.
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width