<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:12pt"><DIV></DIV>
<DIV>An important thing to remember is that what looks complex to you is not necessarily complex to the database. Many people are scared to death of JOINs because they think that makes the statement complex, while, in reality, they often make the statement simpler to the database. Just make sure you (the coder)&nbsp;know the difference between INNER and LEFT JOINs.</DIV>
<DIV>&nbsp;</DIV>
<DIV>And some times, a subquery is the only way to get accurate&nbsp;results. For example, getting a count of matching items from one table based on a selection from another is generally going to give you erroneous (and much slower) results without a subquery.</DIV>
<DIV>&nbsp;</DIV>
<DIV>And I echo the "test more than one solution" sentiment. I usually will pop over&nbsp;to PhpMyAdmin and test a query first to make sure it gives me what I expect. There&nbsp;I can also break out subqueries (and JOINs)&nbsp;to see if they give&nbsp;me what I expect. This is much better than the customer coming back and saying, "Are you sure this&nbsp;screen is right?"<BR>&nbsp;</DIV>
<P><FONT color=#ff007f size=4 face="bookman old style, new york, times, serif"><EM><STRONG>Nancy</STRONG></EM></FONT></P>
<P>&nbsp;</P>
<P><FONT face="arial, helvetica, sans-serif">Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.</FONT></P>
<DIV><BR></DIV>
<DIV style="FONT-FAMILY: arial, helvetica, sans-serif; FONT-SIZE: 12pt"><BR><FONT size=2 face=Tahoma>
<DIV style="FONT-FAMILY: Courier New, monaco, monospace, sans-serif; FONT-SIZE: 10pt">
<HR SIZE=1>
</DIV>
<DIV style="FONT-FAMILY: Courier New, monaco, monospace, sans-serif; FONT-SIZE: 10pt"><B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Pierre Rineau</DIV>
<DIV style="FONT-FAMILY: Courier New, monaco, monospace, sans-serif; FONT-SIZE: 10pt"></FONT><BR>The only suggestion I would give you is don't be afraid of complex SQL<BR>queries, the only important thing is to always use direct (join|where|<BR>etc) conditions over indexed fields.<BR><BR>Sometime subqueries can speedup a complex query, not always, test more<BR>than one solution using EXPLAIN<BR><BR><BR></DIV></DIV></div></body></html>