Hi Nigel, all !

Nigel Peck wrote:
> [[...]]
> 
> My query is:
> 
> SELECT
>     `People`.`person_id`,
>     `People`.`name`
> FROM
>     `People`
> INNER JOIN
>     `Person_postal_addresses`
> ON
>     `Person_postal_addresses`.`person_id` = `People`.`person_id`
> WHERE
>     `People`.`name` REGEXP 'example'
>     OR
>     `Person_postal_addresses`.`address` REGEXP 'example'
> ;
> 
> How do I alter that to get one result per matching row in the People
> table? When there are multiple matches, for one row in People, for:
> 
>     `Person_postal_addresses`.`address` REGEXP '1'
> 
> Thanks in advance,
> Nigel

I see two possibilities:

a)  "SELECT DISTINCT ..."
    http://dev.mysql.com/doc/refman/5.0/en/select.html

b) Use a subquery and an "EXISTS" predicate:
http://dev.mysql.com/doc/refman/5.0/en/exists-and-not-exists-subqueries.html

I expect the subquery approach to be performing worse than the "distict".


HTH,
Jörg

-- 
Joerg Bruehe,  MySQL Build Team,
               joerg.bru...@sun.com
Sun Microsystems GmbH,   Sonnenallee 1,   D-85551 Kirchheim-Heimstetten
Geschaeftsfuehrer: Thomas Schroeder, Wolfgang Engels, Dr. Roland Boemer
Vorsitzender des Aufsichtsrates: Martin Haering     Muenchen: HRB161028


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=arch...@jab.org

Reply via email to