How to return a zero when it is null

0

I have an SQL with two files:

First file PRODUCTS: (PRD) PRODUCT FIELD

Second file STOCK: (PRD2) FIELD PRODUCT, (STOCK) FIELD STOCK

If I do one:

Select  PRD, STOCK   from PRODUCTOS inner join STOCK ON PRD=PRD2

It clearly returns the products that have stock.

But I do not want that. Since there are more records in the product file than in the stock.

If I do it with a left join, I get null as a result in the stock field in the references that being in the first file is not in the second, but I want to put a zero.

I've tried with case ... and coalesce .. but it keeps coming out null. Can you help me?

Thanks

    
asked by Mer 20.08.2018 в 22:35
source

1 answer

1

You do not need when or end, try it like this:

Select prd, coalesce(stock, 0) as Stock from Productos inner join stock on prd-prd2
    
answered by 21.08.2018 в 17:44