0

Can you help me about this sql query about the INNER JOIN. The result return error

connection.query("SELECT caracavis.caracname FROM caracavis WHERE firstcaturl ='" + req.body[0].firstcatname + "' AND secondcaturl = '" + req.body[0].secondcatname + "' AND thirdcaturl = '" + req.body[0].thirdcatname + "' AND fourthcaturl = '" + req.body[0].fourthcatname + "' AND fifthcaturl = '" + req.body[0].fifthcatname + "' INNER JOIN critereproducts ON caracavis.caracname = critereproducts.nameurl", function (error, results, fields) {
				if (!!error) {
					console.log('erreur');
				} else {
					console.log(results);
					// res.json(results);
				};
			});

2
  • What error do you get? Commented Oct 25, 2017 at 19:33
  • What is the error ? Commented Oct 25, 2017 at 19:34

1 Answer 1

4

INNER JOIN comes before WHERE.

SELECT caracavis.caracname
FROM caracavis 
INNER JOIN critereproducts 
ON caracavis.caracname = critereproducts.nameurl
WHERE ...
Sign up to request clarification or add additional context in comments.

2 Comments

It works ! I can't accept now, should wait 7min. thanks
You're welcome. Off on a tangent, but you can do join syntax in the WHERE clause, but you wouldn't use JOIN statements. You'd just list the tables in the FROM clause, then in the WHERE clause you'd enforce the relationship, which is very similar to what you attempted but a mix of the two. Recommended approach is always use ANSI Join syntax, e.g. INNER JOIN, over the old style.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.