I\'m using postgresql 9.1 and wish to select a single record from table. Details are as below :
table name : muser
fields present in table : userid,username,fir
When I'm dealing with filter where the value can be any including null
I'll try add coalesce()
SELECT userid, mailid, phonenumber
FROM muser
WHERE coalesce(phonenumber,'no data') = coalesce(?,'no data')
OR coalesce(mailid,'no data') = coalesce(?, 'no data');
Assuming that when you mean "not present", mailid or phonenumber will be NULL
in database,
SELECT userid, mailid, phonenumber
FROM muser
WHERE (phonenumber = ? AND (mailid IS NULL OR mailid = ''))
OR ((phonenumber IS NULL OR phonenumber = '') AND mailid = ?)
OR (phonenumber = ? AND mailid = ?)