Answer the question
In order to leave comments, you need to log in
How to make a left join if the second table has a condition that removes positions from the first table?
There are 2 tables. Let's say the first table with articles. There is a second table with articles/sales/date. The bottom line is that I need to pull up the amount of sales from the second table from a certain date to the first table.
If I do a left join without the date constraint condition on the second table. That all works well. If there were sales, he shows them. If there is no article in the second table, then it returns Null. All as I need. But if I put a condition that in the second table date>. Then the articles that are in the first table are not shown. in the second table there is a condition date>. How can I make a query so that all the articles from the first table remain. And the sales were summed up from a certain date.
SELECT t1.art, sum(t2.sales) FROM table1 as t1
LEFT JOIN table2 as t2
ON t1.art = t2.art
WHERE t2.date > CONVERT(DATE,'01.01.2021')
GROUP BY t1.art
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question