You are trying to perform two JOINS to match the information of two tables, the first table contains a catalog of articles.
id_art desc
------------------------
A1 Articulo A1
A2 Articulo A2
A3 Articulo A3
A4 Articulo A4
A5 Articulo A5
The second table contains reorder points for most items by branch.
id id_art max pro min
----------------------------------------------
01 A1 0 2 5
02 A1 1 2 4
02 A2 1 2 6
01 A3 1 3 5
02 A3 2 4 6
01 A5 0 2 3
What I need is for the result of the Query to give me the following
id suc max pro min suc max pro min
---------------------------------------------------------------------------
A1 01 0 2 5 02 1 2 4
A2 NULL NULL NULL NULL 02 1 2 6
A3 01 1 3 5 02 2 4 6
A5 01 0 2 3 NULL NULL NULL NULL
Currently the Query that I generated only results in articles that have a record in branch 01 and 02, omitting individual records
id suc max pro min suc max pro min
---------------------------------------------------------------------------
A1 01 0 2 5 02 1 2 4
A3 01 1 3 5 02 2 4 6
I'm trying to organize it with the following Query:
SELECT
a.id_art,
r1.suc,
r1.max,
r1.pro,
r1.min,
r2.suc,
r2.max,
r2.pro,
r2.min
FROM articulos a
RIGHT JOIN(SELECT suc,max,pro,min FROM MMR
WHERE suc='01'
) r1 ON r1.id_art=a.id_art
RIGHT JOIN(SELECT suc,max,pro,min FROM MMR
WHERE suc='02'
) r2 ON r2.id_art=a.id_art
ORDER BY a.id_art
I appreciate your support, I'm a bit lost since it's the first time I've worked with SQL, thanks.