Results 1 to 3 of 3

Thread: SQL query help

  1. #1
    Join Date
    Jun 2008
    Posts
    10

    SQL query help

    Hi,

    I have 2 fields, customer number and lifestage (a,b,c). The lifestage can occur more than once.

    How do I find customers with lifestage that have duplicates. For eg, customer 5 has 2 lifestage (a and a).

    What is the simplest SQl query to acheive this?

    Thanks.

    Nijojo.

  2. #2
    Join Date
    Jul 2008
    Location
    Belgium
    Posts
    17
    Hello

    Can this help you?

    SELECT customernumber, lifestage, COUNT(*) AS amount
    FROM customers
    GROUP BY customernumber, lifestage

    Greetings
    ld_be

  3. #3
    Join Date
    Jul 2008
    Posts
    4
    Hi,

    If you want only the duplicates then you only have to add the HAVING-option.

    SELECT customernumber, lifestage, COUNT(lifestage) AS amount
    FROM customers
    GROUP BY customernumber, lifestage
    HAVING COUNT(lifestage) > 1

    If lifestage can be empty use count(*) instead.

    Kind regards,
    GC

Posting Permissions

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