SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: SELECT & COUNT

  1. #1
    SitePoint Member
    Join Date
    Aug 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SELECT & COUNT

    Hi,

    I need some assistance on selecting and counting records from a database.

    Every record in the table will have a category example 'News' and 'Sport'. Let say News has 17 category's and sport has 11. How can I list all category's and count the total amount of records within that category.

    so. . .

    News (17)
    Sport (11)

  2. #2
    SitePoint Mentor silver trophybronze trophy
    Mikl's Avatar
    Join Date
    Dec 2011
    Location
    Edinburgh, Scotland
    Posts
    1,441
    Mentioned
    58 Post(s)
    Tagged
    0 Thread(s)
    Hmm. Not sure if I understand the question.

    You say "Every record in the table will have a category example 'News' and 'Sport'." But you also say "Let say News has 17 category's and sport has 11." If a record has a category named News, how can News have 17 categories?

    Do you mean that there might be 17 records for which News is the category?

    If so, then to get the number of records in each category, you would do something like this:

    SELECT Category, COUNT(*) FROM TheTable GROUP BY Category

    Does that answer you question?

    Mike

  3. #3
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not really an ASP problem. You may want to post this to an SQL forum They do this type of problem all day long.

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webber123456 View Post
    Not really an ASP problem. You may want to post this to an SQL forum They do this type of problem all day long.
    Thread moved to the databases forum
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by webber123456 View Post
    They do this type of problem all day long.
    all day, and all of the night
    Off Topic:

    bonus points if you can name that song
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,706
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The song was in my head, but couldn't think of who it way by. I'm not posting since I had to look it up.


Tags for this Thread

Bookmarks

Posting Permissions

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