Stop repeat entries

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Damien

    Stop repeat entries

    Can you stop pulling out exactly the same data from a database, for
    example, if you had 2 entries which had the name Chris, it would only
    print Chris once?
  • Joshua Ghiloni

    #2
    Re: Stop repeat entries

    Damien wrote:[color=blue]
    > Can you stop pulling out exactly the same data from a database, for
    > example, if you had 2 entries which had the name Chris, it would only
    > print Chris once?[/color]

    You could use SQL's DISTINCT keyword, but that would only work if every
    row in your resultset would be a match.

    for instance, given the table

    fname | lname
    ------+------
    Chris | Smith
    Chris | Jones

    SELECT DISTINCT(fname) FROM tblName WHERE fname='Chris' would work, where

    SELECT DISTINCT(*) FROM tblName WHERE fname='Chris' wouldn't.

    You might be able to do it with some nasty JOINs but those are evil and
    kill your performance.

    Comment

    • DjDrakk

      #3
      Re: Stop repeat entries

      Actualy, if you are using SQL, I would use a LIMIT command as follows

      SELECT fname FROM table WHERE fname = Chris LIMIT 1;

      --
      Your GP or your HP!
      Warren Butt

      "Joshua Ghiloni" <jdg11@SPAM.ME. AND.DIE.cwru.ed u> wrote in message
      news:bg1ctt$7ia $1@eeyore.INS.c wru.edu...[color=blue]
      > Damien wrote:[color=green]
      > > Can you stop pulling out exactly the same data from a database, for
      > > example, if you had 2 entries which had the name Chris, it would only
      > > print Chris once?[/color]
      >
      > You could use SQL's DISTINCT keyword, but that would only work if every
      > row in your resultset would be a match.
      >
      > for instance, given the table
      >
      > fname | lname
      > ------+------
      > Chris | Smith
      > Chris | Jones
      >
      > SELECT DISTINCT(fname) FROM tblName WHERE fname='Chris' would work, where
      >
      > SELECT DISTINCT(*) FROM tblName WHERE fname='Chris' wouldn't.
      >
      > You might be able to do it with some nasty JOINs but those are evil and
      > kill your performance.
      >[/color]


      Comment

      • Joshua Ghiloni

        #4
        Re: Stop repeat entries

        Joshua Ghiloni wrote:[color=blue]
        > Damien wrote:
        >[color=green]
        >> Can you stop pulling out exactly the same data from a database, for
        >> example, if you had 2 entries which had the name Chris, it would only
        >> print Chris once?[/color]
        >
        >
        > You could use SQL's DISTINCT keyword, but that would only work if every
        > row in your resultset would be a match.
        >
        > for instance, given the table
        >
        > fname | lname
        > ------+------
        > Chris | Smith
        > Chris | Jones
        >
        > SELECT DISTINCT(fname) FROM tblName WHERE fname='Chris' would work, where
        >
        > SELECT DISTINCT(*) FROM tblName WHERE fname='Chris' wouldn't.
        >
        > You might be able to do it with some nasty JOINs but those are evil and
        > kill your performance.
        >[/color]

        Yes forget I said all this. I've been at work too long today, and I'm
        tired :)

        Comment

        Working...