i have 2 tables one (visits) and other one (patients) with relationship by mysql (patients) is with PK as patients.pid and visits.pid as index and i wanted to use code in my vb.net app to get the last datetime record to check the patient if still inside the hospital admitted or discharge so far i have this code with help of you guys
SELECT a.pid,MAX(ISNULL(b.sdat,'1901-01-01')),MAX(ISNULL(b.edat,'1901-01-01')) from patients a left join visits b on a.pid=b.pid Where ddatediff(now(),b.edat) <=365 group by a.pid
but when i execute in sql builder using php myadmin or another app i get error (1582 - Incorrect parameter count in the call to native function 'ISNULL') i tried to find out the error cause but no luck until now
MySQL's ISNULL()
is a comparison function, that takes a single argument and returns 1
if it is NULL
. I think that you meant IFNULL()
- or the more standard COALESCE()
.
I would also suggest moving the check outside of the aggregate function, for better efficiency:
COALESCE(MAX(b.sdat),'1901-01-01'),
COALESCE(MAX(b.edat),'1901-01-01')