I have for example as first query: (ararnr = article number)
Select ararnr,ararir,aoarom from ar left join ao ON AR.ARARNR=AO.AOARNR WHERE AR.ARARKD=1389
the second query uses the result from the first column from the first query to search in another table
Select votgan, sum(ststan) as totalStock from vo INNER JOIN st on vo.voarnr=st.starnr where voarnr = ararnr
How could I combine both ?
Please note : Not all articlenumbers from the first query will be found in the second, but I need them in my result.
In the result I need the columns from both queries.
EDIT
for example :
first query returns article numbers and the description:
+---------+--------------+ | ararnr | aoarom | +---------+--------------+ | a123456 | description1 | | b123456 | description2 | | 0123456 | description3 | +---------+--------------+
second query returns the totalstock for those articles:
+---------+--------------+ | ararnr | totalstock | +---------+--------------+ | a123456 | 12 | | b123456 | | | 0123456 | 6 | +---------+--------------+
Note the second one doesn't return a value since the articlenumber doesn't exist in this table.
In my result I would like to get the articlenumber with corresponding description and stock.
+---------+--------------+-----------+---------+ | ararnr | aoarom | totalStock| vovoan | +---------+--------------+-----------+---------+ | a123456 | description1 | 12 | 2 | | b123456 | description2 | | 1 | | 0123456 | description3 | 6 | | +---------+--------------+-----------+---------+
I'm using sql on db2
SECOND EDIT
The first query will select some article numbers (ararnr) from table ar and find the corresponding description (aoarom) in another table ao.
The second query finds the stock (vovoan and sum ststan) from two differend tables vo and st for the article numbers found in the first query.
The result should have the article number with corresponding description with corresponding stock from vo and st