Thanks Paul!
ps works great!
I modified the database with a UNIQUE column like you recommended
earlier, this will now help in the PHP script to trap the duplicate
entry and advise the user of the dup.
<?
// check for duplicate row
$query = "SELECT hostname, COUNT(*) AS count FROM asset
GROUP BY hostname HAVING count > 1
$result = mysql_query($query);
// check if row is returned, if yes error, if no insert
if (mysql_num_rows($result) != 0) {
echo "error";
} else {
// DO INSERT
}
?>
Pete
Paul DuBois wrote:
>
> At 3:13 PM -0500 6/27/01, Pete Kuczynski wrote:
> >Hi,
> >How would a word a select statment, to search a database for duplicate
> >entries in one field.
> >
> >For example, the fields: device, hostname, IP, comments
> >
> >I want to find all instances where there my be two devices with the same
> >hostname.
>
> SELECT hostname, COUNT(*) AS count FROM tbl_name
> GROUP BY hostname HAVING count > 1
>
> >
> >Thanks!
> >
> >Pete
> >--
> >_______________________________________
> >Pete Kuczynski
> >Principal Field Engineer
> >DHL Airways Inc.
> >Infrastructure Technology & Services
> >(773)-462-9758
> >24/7 Helpdesk 1-800-434-5767
>
> --
> Paul DuBois, [EMAIL PROTECTED]
--
_______________________________________
Pete Kuczynski
Principal Field Engineer
DHL Airways Inc.
Infrastructure Technology & Services
(773)-462-9758
24/7 Helpdesk 1-800-434-5767
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php