Skip to main content
Inspiring
June 20, 2008
Answered

Determine Number of times record exists

  • June 20, 2008
  • 3 replies
  • 675 views
I'm sure there is an easy way to do this but I'm totally blanking today and REALLY need the board's help.

I have multiple listing numbers for properties in an Access DB. I need to output the listnumber and how many times it occurs in the table.

Table name is Stats
Table fields are AutoID, Listnumber, Name

The listnumber is a 4 digit number & can be in the table multiple times (it always has the same name attached to it)

I just need the output to say Listnumber is _____ and is in the table _____ times [FOR EACH listnumber]

Thanks SOOO much in advance for your help!
    This topic has been closed for replies.
    Correct answer Firebug_web
    Ian Skinner - You get the GOLD STAR! That setup worked perfectly!

    Thanks everyone for the assistance, I will try to do the same when I have the answer

    .

    3 replies

    tclaremont
    Inspiring
    June 20, 2008
    Like Dan suggests, if you want ALL of them, use Group By. If you want a specific one, use the where statement.

    Suggestion: "Sams Teach Yourself SQL in 10 Minutes - By Ben Forta" Available used on Amazon.com for under ten bucks.
    tclaremont
    Inspiring
    June 20, 2008
    SELECT Count(AutoID) As ListNumberCount
    FROM Stats
    WHERE ListNumber = Whatever
    Inspiring
    June 20, 2008
    My problem is:

    WHERE listnumber =whatever

    I dont want to say where listnumber = 1234 because I want the count of how many times 1234 exists IN ADDITION to how many times 1235, 1345, 1356, etc exist.
    Inspiring
    June 20, 2008
    Use group by then:-

    SELECT AutoID, Count(AutoID) As [count]
    FROM Stats
    GROUP BY AutoID
    Inspiring
    June 20, 2008
    select f1, f2 count(f1) yourcount
    from yourtables
    where your_conditions_are_met
    group by f1, f2