SunQuest
           Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 1st, 2002, 08:31 AM
bm82 bm82 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: UK
Posts: 9 bm82 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to bm82
How do u select records where two or more fields are the same?

Hi,

Need some help with a little SQL code.

I have a table with fields:

id
username
password

I want to select all records where there are two or more equal passwords. Is it possible?

(in case it may help Im using MySQL)

Reply With Quote
  #2  
Old September 1st, 2002, 01:28 PM
donarb donarb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 1999
Location: Seattle
Posts: 133 donarb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
You can always join a table to itself for comparison purposes. This code assumes that your table is called mytable and that id is unique.

SELECT DISTINCT t1.id, t1.name, t1.password
FROM mytable t1, mytable t2
WHERE t1.password = t2.password and t1.id != t2.id

Don

Reply With Quote
  #3  
Old September 1st, 2002, 01:43 PM
bm82 bm82 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: UK
Posts: 9 bm82 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to bm82
That didnt seem to work for me.

I figured our part of it.

SELECT password FROM table
GROUP BY password HAVING count( * ) > 1

But that returns all passwords which are used more than once, which ispartly what I want. Im having to then make a query for each of those passwords returned by the above to get the rest of the table information.

Its slow. There is another method, using "In" (Im guessing a query in a query), but MySQL doesnt seem to want to support it.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > How do u select records where two or more fields are the same?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway