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?
 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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
All Courses

From novice to tech pro — start learning today.