Question: So, I have some data that needs to be count with RIGHT JOIN. The query look like this:

```
SELECT COUNT(trans_id) FROM database2..transaction a
RIGHT JOIN database1..sellers b
ON a.products = b.products
GROUP BY sellers
ORDER BY sellers

```

The result ends up perfectly like this one:

[![enter image description here](https://i.stack.imgur.com/ZfaRH.png)](https://i.stack.imgur.com/ZfaRH.png)

As you can see, there are 10 names on the result and there are 3 zero results because it was NULL data in my database. 

And then I tried to add some conditions on the query, like this:

```
SELECT COUNT(trans_id) FROM database2..transaction a
    RIGHT JOIN database1..sellers b
    ON a.products = b.products
WHERE trans_status = 'success'
    GROUP BY sellers
    ORDER BY sellers

```

The result ends up differently:

[![enter image description here](https://i.stack.imgur.com/Mt0rv.png)](https://i.stack.imgur.com/Mt0rv.png)

It ended up with 6 results only. And the zero count on before was gone after I add up some conditions. Does that mean SQL only count existed data only even though I added up condition like that?

Answer: 
Your `WHERE` clause is applied after your `JOIN`. If you want the 0 counts to still show up, you should add it to your `JOIN` instead. 

```
SELECT COUNT(trans_id) FROM database2..transaction a
    RIGHT JOIN database1..sellers b
    ON a.products = b.products
       AND trans_status = 'success'
    GROUP BY sellers
    ORDER BY sellers

```
They were likely dropped by this condition: "WHERE trans\_status = 'success'".

Instead of WHERE clause, try this condition in the ON clause of the JOIN. Something like this:

```
SELECT COUNT(trans_id) FROM database2..transaction a
    RIGHT JOIN database1..sellers b
    ON a.products = b.products AND trans_status = 'success'
    GROUP BY sellers
    ORDER BY sellers

```