![]() |
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: :
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. |
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 |
Re: Select Non distinct in MySQL
Was going to recommend exactly that.
Having Count > X is a useful query. |
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 |
Re: Select Non distinct in MySQL
SELECT primarymac, COUNT(*) as count
FROM aidahardware GROUP BY primarymac HAVING count > 1 Sanjay Aggarwal |
Re: Select Non distinct in MySQL
Once again, Sanjay Aggarwal manages to regurgitate information identical to what has already been posted in a thread.
|
Re: Select Non distinct in MySQL
Quote:
Unknown column 'count' in 'where clause' |
Re: Select Non distinct in MySQL
Ok so my original code looked right except I wanted everything so this is what worked for me:
:
|
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 :
|
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. |
| All times are GMT -5. The time now is 3:43 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC