My question i need Mysql Query if there is no value found in any table then i want to return the result value to zero else the value which i found.
i tried out every solution every solution which is provided by ChatGPT but i am failed to get my specific result
i tried out,
SELECT IF( EXISTS( SELECT RepairingId FROM expenses where WorkDate='2023-07-23 00:00:00' and VehRegNo='PB-56B-8508'), 1, 0) AS RepairId;` -- this is working but i want the value of RepairingId not just 1
SELECT IFNULL(RepairingId, 0) AS result FROM expenses where WorkDate='2023-07-24 00:00:00' and VehRegNo='PB-56B-8508';` -- this give me no value
SELECT CASE WHEN RepairingId IS NOT NULL THEN RepairingId ELSE 0 END AS resultFROM expenses where WorkDate='2023-07-24 00:00:00' and VehRegNo='PB-56B-8508'; -- this give me no value
2
Answers
try
or
or
Try this:
You can see my example in dbfiddle