#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Not showing duplicate last names in my database


    Hi everyone,

    This is probably a pretty easy question/solution but I couldnt figure it out so I had to ask for help...

    I have a php mysql database at (www dot homebasebuffalo dot com) which lists area highschool athletes who have gone on to college or professional programs. The problem I realized is that I am ordering them by last name in the database - and it is not allowing for Duplicate last names. So if there are 5 'Smiths' (all different people with different info in the rest of the table) it will only show one.

    Is there a simple and or not so simple way of fixing this??
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Sep 2006
    Posts
    1,986
    Rep Power
    533
    It probably has to do with your SQL query and not PHP. Check your query and see if it includes the DISTINCT key word.
  4. #3
  5. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,166
    Rep Power
    4274
    pro tip for getting help with a mysql query: show your query
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    It seems to be happening when I import my .csv into the MYsql ... its not importing duplicate last names (it has no problem importing duplicate other fields)

    my query is ...

    $sql = "SELECT * FROM main ORDER BY last";

    So I dont think its in the mysql query as much as the import. Does it matter that my "last" field is set to primary?
  8. #5
  9. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,166
    Rep Power
    4274
    Originally Posted by walfredocreativ
    Does it matter that my "last" field is set to primary?
    yup

    primary keys are unique by definition

    please do a SHOW CREATE TABLE and i'll help you fix it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    while googling how to do a SHOW CREATE TABLE I ended up just changing the primary field and it now is uploading perfectly. Thank you very much for the help. Sometimes its the little simple things that can be hardest to find fixes to.

IMN logo majestic logo threadwatch logo seochat tools logo