Re: Query - multiple joins won't return any records
Posted by:
Rick James
Date: February 14, 2015 11:39PM
It may take a couple of iterations to figure this out.
> ON relations.FieldID = 1 AND relations.ValID = divisions.ID
relations.ValID = divisions.ID -- This sounds "right" for the ON-clause of the JOIN, but
relations.FieldID = 1 -- sounds like something that should be in the WHERE clause; please move it to there (unless there is a valid reason for keeping it in the ON-clause). There are cases where it matters. (I don't know about this case.)
Ditto for the other ON-clause.
Remove extra parentheses from around the JOINs; they confuse me, and maybe the optimizer. That is, use this pattern (again, unless there is a valid reason for what you have):
FROM x
JOIN y ON ...
JOIN z ON ...
WHERE ...
GROUP BY ...
ORDER BY ...
Do not use DISTINCT and GROUP BY in the same SELECT. You probably want GROUP BY since there is an aggregate.
Either use InnoDB (not MyISAM) or get rid of the FOREIGN KEYs (since MyISAM ignores them).
I would prefer `RecordID` be changed to the conventional `id`, but I won't insist on that.
After you have made those changes, I will try to analyze your problem. (It is remotely possible that one of my suggestions will fix the problem!)
Subject
Written By
Posted
February 13, 2015 09:32PM
February 14, 2015 10:21AM
February 14, 2015 10:57AM
February 14, 2015 03:03PM
February 15, 2015 01:40AM
February 15, 2015 09:59AM
February 15, 2015 01:40PM
February 15, 2015 02:33PM
February 15, 2015 02:54PM
February 15, 2015 03:09PM
February 15, 2015 07:59PM
February 19, 2015 03:06PM
February 19, 2015 04:17PM
February 21, 2015 07:01PM
Re: Query - multiple joins won't return any records
February 14, 2015 11:39PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.