Re: Still bugging me..
| From: | Brian T. Allen | Date: | Sat, 12 Aug 2000 19:19:23 +0000 |
| Subject: | Re: Still bugging me.. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11473@lists.php.net to get a copy of this message | ||
Yeah, you should be able to do something like (off the top of my
non-mysql-expert head):
SELECT * FROM TABLE_A,TABLE_B,TABLE_C WHERE TABLE_A.REFERENCE =
TABLE_B.REFERENCE AND TABLE_A.REFERENCE = TABLE_C.REFERENCE AND {other
search parameters } { sort/order/limit clause }
Make sure you replace * with a list of the actual fields you need to return,
as this will drastically improve the performance of your query.
Also, if you make sure every field in each of your tables is unique (I use
A_ID,B_ID,C_ID, etc so that the columns in each table are prefaced with a 2
or 3 letter prefix unique to that table) you can avoid using TABLE.COLUMN
and just use COLUMN instead. It makes your queries much easier to read (as
does aliases for table names).
Brian
> David,
>
> Are all of these queries coming from the same database? If so, could you
> be using a join of some sort? I prefer natural joins, but even a union
> would probably (maybe, maybe, maybe) be more efficient than what you are
> doing.
>
> Hans
>
> On Fri, 11 Aug 2000, David VanHorn wrote:
>
> >
> > I have the results of three mysql queries, which may contain zero or
more
> > (or many many more) records.
> > I'm trying to find an efficient way to trim this set and only look at
those
> > which have one field in common.
> >
> > IOW:
> >
> > After three queries, I have these sets:
> >
> > $Result_A
> > $Result_B
> > $Result_C
> >
> > Each has a field called reference, (plus several other fields) and the
> > records within Result_A might have reference = 10,11,12,13. Result_B
might
> > have reference = 11,12,13,14, and $Result_C might have reference =
> > 12,13,14,15,16
> >
> > What I want is to discard, or to only pay attention to the records where
in
> > this case, reference is 12 or 13.
> > The problem is that I have to search on other fields in the records to
find
> > out which are potentially interesting.
> >
> > I do need all the data for the congruent set though, not just the
reference
> > numbers, although I suppose I could then re-fetch them, but it seems a
waste.
> >
> > In some cases, these may be large sets, so I really don't want to loop
> > through. If each returned 1000 records, then the result would be a
> > frighteningly large search.
> >
> > --
> > Where's dave?
> > http://www.findu.com/cgi-bin/find.cgi?kc6ete-9
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
> >
> >
>
> Hans Anderson ~ me@hansanderson.com
> PO Box 426, Missoula, MT 59806 | PHP, Search Engines, SQL
> (800)397-9116 / (406)549-6524 | Databases, Flash Multimedia,
> http://www.hansanderson.com | Killer Audio Production,
> http://www.goofiness.com | Minty Fresh Breath.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net