Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61

    Unanswered: SQL Select Problem

    I have a db full of articles that have a category field with the name of the category the articles are from.

    Is there anyway to select and display just the different types of categories on the db?

    What I am trying to do is make a list of the categories in the database without already knowing which categories there are so I can make a menu with links.

    Somebody said Joins do this but I am not familiar with them.
    Mr. Lars

  2. #2
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61
    Just found out that joining isn't the answer. I only have one table...
    Mr. Lars

  3. #3
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    You can actually join a table to itself. However, if I understand what you want, you don't need to use a join.

    If you have a table with a category column, and you want to get a list of distinct categories, the following query will work (note: You can only select the column that you want a distinct list of. If you add a second column to the SELECT list, it will be considered when looking for distinct results.)

    SELECT DISTINCT category FROM your_table GROUP BY category

  4. #4
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61
    BEAUTIFUL. Thanks so much.
    Mr. Lars

  5. #5
    Join Date
    Jun 2003
    Location
    Minnesota
    Posts
    61
    what does "GROUP BY" do?

    If it is selecting distinctly then why do you need to group them when there would be nothing to group it with?
    Mr. Lars

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    exactly

    this is too much -- SELECT DISTINCT category FROM your_table GROUP BY category

    it should be either this -- SELECT DISTINCT category FROM your_table

    or this -- SELECT category FROM your_table GROUP BY category
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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