![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Posts: 27
Rep Power: 0
![]() |
Select Non distinct in MySQL
Hi all,
I know this isn't exactly PHP but I was wondering if there's a simple MySQL query you can use to get back non-distinct lines... like for example you can use SELECT DISTINCT to only give you back the rows with that unique value in a field or whatever... but I'm looking to do the opposite.. I can filter the data with PHP if needs be but I'd much prefer to only get the correct data from the SQL instead and leave unneeded programming out of it... I have a field called mac address on my DB and there are duplicate items and I simply want to be able to pull up details for the mac addresses that are reported twice so I can remove old data from the DB.... for example, if I wanted to get back unique mac addresses on the DB only I would do this: php Syntax (Toggle Plain Text)
but how do I do the exact opposite?? Any help is much appreciated as I cannot find the answer I'm looking for through google etc. |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Nov 2007
Posts: 27
Rep Power: 0
![]() |
Re: Select Non distinct in MySQL
I tell a lie, I've just found what I think I'm looking for :
SELECT primarymac, COUNT(*) as count FROM aidahardware GROUP BY primarymac HAVING count > 1 |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 227
Rep Power: 4
![]() |
Re: Select Non distinct in MySQL
Was going to recommend exactly that.
Having Count > X is a useful query. |
|
|
|
|
|
#4 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 550
Rep Power: 4
![]() |
Re: Select Non distinct in MySQL
Don't know about MySql but Sybase database the having clause can be somewhat slow, so I would code with the where clause
SELECT primarymac, COUNT(*) as count FROM aidahardware where count > 1 |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Oct 2007
Posts: 12
Rep Power: 0
![]() |
Re: Select Non distinct in MySQL
SELECT primarymac, COUNT(*) as count
FROM aidahardware GROUP BY primarymac HAVING count > 1 Sanjay Aggarwal |
|
|
|
|
|
#6 |
|
Expert Programmer
|
Re: Select Non distinct in MySQL
Once again, Sanjay Aggarwal manages to regurgitate information identical to what has already been posted in a thread.
|
|
|
|
|
|
#7 | |
|
Newbie
Join Date: Nov 2007
Posts: 27
Rep Power: 0
![]() |
Re: Select Non distinct in MySQL
Quote:
Unknown column 'count' in 'where clause' |
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Nov 2007
Posts: 27
Rep Power: 0
![]() |
Re: Select Non distinct in MySQL
Ok so my original code looked right except I wanted everything so this is what worked for me:
sql Syntax (Toggle Plain Text)
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Nov 2007
Posts: 27
Rep Power: 0
![]() |
Re: Select Non distinct in MySQL
Well I have this code working great now except for one thing... I can't get a number of how many results coming back from the DB and store it to a variable. see my variable $total_results... what am I doing wrong?
Error message is supplied argument is not a valid MySQL result resource in non_unique_mac.php php Syntax (Toggle Plain Text)
|
|
|
|
|
|
#10 |
|
Programming Guru
![]() |
Re: Select Non distinct in MySQL
Wow. Slow down. Use
int mysql_num_rows ( resource $result ) if you want to get the number of results for a query. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Connecting MySQL and PHP | titaniumdecoy | PHP | 10 | Feb 25th, 2008 7:47 PM |
| MySql | paulchwd | Other Web Development Languages | 8 | Feb 8th, 2007 9:17 PM |
| Better way to Select from MySQL? | Xeoncross | PHP | 3 | Oct 3rd, 2006 3:48 PM |
| SQL select distinct | OpenLoop | Other Programming Languages | 2 | Apr 10th, 2006 8:30 PM |
| Tutorial - Using MySQL in C# | Darkhack | C# | 12 | Jan 17th, 2006 9:28 AM |