Results 1 to 6 of 6

Thread: MySQL Unique Question

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    MySQL Unique Question

    I need a refresher here. Let's say I want to select from a database where the user='blah' and subscribe='1' but there will be multiple entries for that user. This is for the boards I'm working on, if you need a better picture of what I'm doing.

    So can I do:

    Code:
    SELECT UNIQUE user, subscribe WHERE user='blah' AND subscribe='1'
    Or:

    Code:
    SELECT UNIQUE user WHERE user='blah' AND subscribe='1'
    Or...?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    oh, it's DISTINCT, isn't it?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    why use distinct if you have the where clause looking for a specific user?

    and you let users have the same user name as everybody else?

    distinct looks for words that have multiple copies of itself and gets just one.

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    because there can be more than one entry (more than one post) in table for that user with the same parent.

    I figured it out. Works perfectly with distinct. Without it, it would return:

    The Hobo
    The Hobo
    The Hobo

    and I would get three subscription e-mails. Distinct limits that to one unique username in the result.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    ahh sorry that makes since. helps to know what you were trying to do and how many results you were trying to get. I assumed (shame on me) that you only wanted one result.

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    ahh sorry that makes since. helps to know what you were trying to do and how many results you were trying to get. I assumed (shame on me) that you only wanted one result.
    Sorry about that.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width