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";
anotherdotcommerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
rationalbossConnect With a Mentor Commented:
If you just want to list the usernames, you can use the following queries:

SELECT DISTINCT(username) FROM users;

-or-

SELECT * FROM users GROUP BY username;
0
 
Chris HarteThaumaturgeCommented:
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.
0
 
anotherdotcommerAuthor Commented:
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?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
rationalbossCommented:
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

0
 
Lukasz ChmielewskiCommented:
0
 
anotherdotcommerAuthor Commented:
I need to do it somehow do it without deleting any of the rows..... Is there any way?
0
 
anotherdotcommerAuthor Commented:
Thanks!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.