SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting unique entries in a DB.

    How would you select 1 of an entrie in a db..

    I want to select and echo a list of things, ignoring all of the duplicate entries. How would i do this? Is there a sql syntax enabling you to do this?

    Thanks in advance.

    -Cordy

  2. #2
    SitePoint Wizard HarryR's Avatar
    Join Date
    Dec 2004
    Location
    London, UK
    Posts
    1,376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    This probably isn't the correct forum to be posting in (e.g. the 'Program Your Site -> Databases' forum would be a better place), and you haven't provided much information to go on other than you're using 'a database'. So I'll presume you're using the PHP norm (MySQL).

    You can perform grouping of columns by using the 'GROUP BY' keyword as described in the MySQL reference manual. For example:

    Code:
    mysql> SELECT year, SUM(profit) FROM sales GROUP BY year;
         +------+-------------+
         | year | SUM(profit) |
         +------+-------------+
         | 2000 |        4525 |
         | 2001 |        3010 |
         +------+-------------+
    This would provide the totals of all sales in each year, grouped by the year itself.

    For more information about the MySQL 'GROUP BY' keyword please use http://dev.mysql.com/doc/mysql/en/gr...modifiers.html

    Regards,
    Harry

  3. #3
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT DISTINCT(column), FROM table WHERE condition='met'


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
  •