Link to home
Start Free TrialLog in
Avatar of anotherdotcommer
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
anotherdotcommer

ASKER

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;

DROP TABLE users;

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?
ASKER CERTIFIED SOLUTION
Avatar of rationalboss
rationalboss

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