I'm building an Accounting Web Project using Nodejs and Express and I have to connect three tables from my database: parametro, tipoparametro and clasificacion.
My original query allows two tables to connect with the following code:
const parametro = await pool.query('SELECT p.parid, p.parcodigo, p.parclasificacion, tp.tipoparcodigo, p.parvalor, p.pardescripcion, p.parfechacrea FROM parametro p join tipoparametro tp WHERE p.tipoparid = tp.tipoparid ORDER BY p.parid DESC');
However, I need to add table clasificacion, but adding the second join breaks the code. Looks like this:
const parametro = await pool.query('SELECT p.parid, p.parcodigo, p.parclasificacion, c.parletras, tp.tipoparcodigo, p.parvalor, p.pardescripcion, p.parfechacrea FROM parametro p join tipoparametro tp WHERE p.tipoparid = tp.tipoparid join clasificacion c where c.parclasificacion = p.parclasificacion ORDER BY p.parid DESC');
I get the following error:
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'join clasificacion c where c.parclasificacion = p.parclasificacion ORDER BY p.pa' at line 1
The query works fine in SQL but not inside my router.get await request.
I have searched but found no useful examples for multiple joins inside the same query for pool.query. In the future, I may even require more complex queries for my project. Is the SQL syntax incorrect, or am I missing something in order to add several tables together?