1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Rep Power
    I don't know how to select rows which have only one column distinct, other columns may be equal. So SELECT DISTINCT doesn't work.

    Table has columns 'name' and 'email'.
    SELECT DISTINCT name, email FROM table
    still gives me rows with same email (but different name). I want only one row in the set for each email.

    Do I need some inner join? Please help.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Rep Power
    The problem here is that you're kind of asking the database to do more than it knows how to. How is the database supposed to determine _which_ row it should return? If you have three email addresses for one name, how does the DB know which one should be returned? If you add a 'primary_email' column to your table and query and set that on the row that represents a single persons primary email address then you'll get the right result. Alternatively, bring all the results back into your application logic and select whatever row you feel is best.

Similar Threads

  1. selecting all fields while using distinct ?
    By spackbace in forum Database Management
    Replies: 4
    Last Post: January 8th, 2004, 07:12 AM
  2. SELECT DISTINCT returns all rows in table
    By C3P0 in forum MySQL Help
    Replies: 5
    Last Post: October 22nd, 2003, 05:05 AM
  3. Count amount of rows in same query of selecting rows
    By JasonL in forum PHP Development
    Replies: 2
    Last Post: October 15th, 2003, 11:04 AM
  4. Selecting random from the 10 last rows
    By kid in forum MySQL Help
    Replies: 4
    Last Post: June 27th, 2002, 10:20 PM
  5. Replies: 1
    Last Post: September 27th, 2001, 06:49 AM

IMN logo majestic logo threadwatch logo seochat tools logo