Gazing into my crystal ball I observed "CodingCyb.org"
writing in
79a3b0e0d46a DeleteThis @r31g2000vbi.googlegroups.com:
> Well, I ended up getting it to work after moving the SUM and AVG
> inside of what I found out is called a SubQuery.
>
> As for my layout, for my php/html/javascript I always do nice
> indentations. But with SQL I typically only use short queries with few
> parts so haven't had much of a need to break them down. Now that I am
> getting into more precise queries I should probably get into a habit
> of making them look cleaner.
>
> This is what it ended up being:
>
> mysql_query("SELECT * FROM t1 WHERE ".
> "(SELECT SUM(dcNum) FROM t2 WHERE t2.dcDeck = t1.deckID) ".
> ">= 40 ORDER BY ".
> "(SELECT AVG(drRate) FROM t3 WHERE t3.drDeck = t1.deckID) ".
> "DESC LIMIT 5");
Yeah, that's still a mess. It's a mixture of PHP syntax and MySQL. It's
better to just post the query itself, like so:
SELECT * FROM t1
WHERE
(SELECT SUM(dcNum) FROM t2
WHERE t2.dcDeck = t1.deckID)
=>40
ORDER BY
(SELECT AVG(drRate) FROM t3
WHERE t3.drDeck = t1.deckID)
DESC LIMIT 5
There is also the problem with using SELECT *, which is not a good practice
for many reasons [http://lmgtfy.com/?q=why+SELECT+*+is+bad].
--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
>> Stay informed about: Want data from t1 based on data in t2 and t3.