Link to home
Start Free TrialLog in
Avatar of anotherdotcommer

asked on

How do I select a unique ID number? PHP

On my website it displays a bunch of different users. but when the user is creating an account the query messes up once in a while and inserts the information twice into the database.
So when it displays it, it displays that user twice. Is there a way to weed out duplicates in the SELECT command, when I'm running the query? I tried SELECT DISTINCT but that didn't do it... Right now it looks like this: $query = "SELECT DISTINCT user FROM users";
Avatar of Chris Harte
Chris Harte
Flag of United Kingdom of Great Britain and Northern Ireland image

The information has been entered twice into the database. The only difference will be the key index. You will have to go into the database and delete the duplicate.
Avatar of anotherdotcommer


I can't go into the database and delete the extras, there are way to many.
So there isn't a way to sort out the duplicates by the username, or another unique row?
Run this on mysql :)

CREATE TABLE users2 as
SELECT * FROM users GROUP BY username;


RENAME TABLE users2 TO users;

Open in new window

I need to do it somehow do it without deleting any of the rows..... Is there any way?
Avatar of rationalboss

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial