MySQL Forums
Forum List  »  General

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!)

Options: ReplyQuote




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.