The Hermit Hacker <[EMAIL PROTECTED]> writes:
> 2EXPLAIN SELECT distinct s.gid, s.created, count(i.title) AS images
>               FROM status s LEFT JOIN images i ON (s.gid = i.gid AND i.active), 
>relationship_wanted rw
>              WHERE s.active AND s.status != 0
>                AND EXISTS ( SELECT gid
>                                 FROM relationship_wanted
>                                WHERE gender = 1 )
>                AND EXISTS ( SELECT gid
>                                 FROM personal_data
>                                WHERE gender = 0
>                                  AND ( ( age('now', dob) > '26 years' ) AND ( 
>age('now', dob) < '46 years' ) )
>                                  AND country IN ( 'US' ) )
>           GROUP BY s.gid,s.created
>           ORDER BY  images desc;

I don't understand what you're trying to do here.  The inner SELECTs
aren't dependent on anything in the outer query, so what are they for?

> ... status and
> personal_data have a 1-to-1 relationship,

Then why have two tables?  Merge them into one table and save yourself a
join.

Also, since status.gid is (I assume) unique, what's the use of the
DISTINCT clause at the top level?  Seems like that's costing you
a useless sort & unique pass ...

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly

Reply via email to