RE: [PHP] Getting Similar rows from db
| From: | Brad Fuller | Date: | Fri, 23 Feb 2007 19:17:40 +0000 |
| Subject: | RE: [PHP] Getting Similar rows from db | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-249305@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Jay Blanchard [mailto:jblanchard@pocket.com]
> Sent: Friday, February 23, 2007 1:51 PM
> To: Wikus Möller; php-general@lists.php.net
> Subject: RE: [PHP] Getting Similar rows from db
>
> [snip]
> I need a script that selects all similar rows from a database. Like
> only the id would differ, but other fields would be the same as other
> rows's fields.
>
> I don't know if there is such a mysql statement like SELECT SIMILAR ....
>
> Please assist me with using the right mysql statement or using php to
> get similar rows from the db.
> [/snip]
>
> See http://www.mysql.com/like
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Assume you have the following data:
ID FirstName LastName
1 John Doe
2 John Doe
3 Jack Black
4 Adam Jones
5 Sally Smith
The following query:
SELECT COUNT(ID) AS NumRecords, FirstName, LastName
FROM MyTable GROUP BY FirstName, LastName HAVING COUNT(ID) > 1;
Would produce the following result:
NumRecords FirstName LastName
2 John Doe
HTH,
Brad