Thread: Query quandry

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    14
    Is there a method by which I can query a table feild and return 'representatives' of each peice of data? I may need to explain further, so let me give a basic example:

    In my fictional musicdatabase table there are thousands of entries under the 'bandname' column. I want to perform a query that will list each unique artist, whether there is 100 instances or just a single entry.

    This query would be printed to a list on the screen.

    TIA,
    - Mike
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Seaside, CA
    Posts
    84
    Rep Power
    15
    "SELECT bandname, COUNT(*) as bttl FROM yourtablename GROUP BY bandname"

    Then you can print both the bandname and how many entries there are for that band/artist.



    ------------------
    From the day we're born, we're running out of time.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    14
    If I may ask, what do the letters 'bttl' do?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Seaside, CA
    Posts
    84
    Rep Power
    15
    It's just an arbitrary name (short for band total) to use for the variable. With that select statement, you have two to use:

    $bandname (the name of the band)
    $bttl (the total entries for that band)

Similar Threads

  1. query syntax error
    By collegebloke in forum MS SQL Development
    Replies: 1
    Last Post: January 19th, 2004, 04:08 PM
  2. Overwriting mysql query with the query results
    By onerandomday in forum PHP Development
    Replies: 1
    Last Post: January 14th, 2004, 04:45 AM
  3. Syntax error in INSERT INTO query
    By Lee Miles in forum Visual Basic Programming
    Replies: 6
    Last Post: December 19th, 2003, 07:37 AM
  4. nested query and MySQL query
    By lucipher in forum MySQL Help
    Replies: 1
    Last Post: November 19th, 2003, 10:49 AM
  5. extremely inconsistent query times
    By mtnman in forum MySQL Help
    Replies: 0
    Last Post: October 23rd, 2003, 12:29 AM

IMN logo majestic logo threadwatch logo seochat tools logo