1

So, I have this sql:

SELECT program.BilanganTerhad - IFNULL(COUNT(daftarprogram.KodProgram), 0) AS kiraan
FROM program, daftarprogram
WHERE program.KodProgram = daftarprogram.KodProgram
  AND daftarprogram.KodProgram = '19'

How can I set the null COUNT() value to 0? For example: 10 - null = null instead of 10 - 0 = 10.
I need the count become 0, not null.

This is value from table1

While this is value from table2

table1 full table 2 I want to subtract value from table1 and minus with count(kodprogram)

The thing is I want to subtract value from table1 with count(KodProgram) from table2 based on where condition = KodProgram

Kucen
  • 11
  • 2

1 Answers1

0

COUNT() never returns NULL. That said, your query is malformed (in addition to using archaic join syntax. BilanganTerhad is in the SELECT but it is an aggregation query.

Perhaps you intend:

SELECT p.BilanganTerhad - COUNT(*) AS kiraan
FROM program p JOIN
     daftarprogram dp
    ON p.KodProgram = dp.KodProgram 
WHERE dp.KodProgram = '19'
GROUP BY p.BilanganTerhad;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • The things is I want to subtract between 2 table.. which is table1.BilanganTerhad - MINUS with COUNT(table2.KodProgram) – Kucen Jun 10 '20 at 11:42