How to return null value if the query has no corresponding value?

Posted by Holicreature on Stack Overflow See other posts from Stack Overflow or by Holicreature
Published on 2010-06-09T14:34:01Z Indexed on 2010/06/09 14:42 UTC
Read the original article Hit count: 164

Filed under:
|

Hi

i've a query

select c.name as companyname, u.name,u.email,u.role,a.date from useraccount u,
company c, audittrial a where u.status='active' and u.companyid=c.id and 
(u.companyid=a.companyID and a.activity like 'User activated%' and 
a.email=u.email) order by u.companyid desc limit 10

So if the following part doesnt't satisfy,

(u.companyid=a.companyID and a.activity like 'User activated%' and 
a.email=u.email)

no rows will be returned..

but i want to return the result of the following query

select c.name as companyname, u.name,u.email,u.role,a.date from useraccount u,
company c, audittrial a where u.status='active' and u.companyid=c.id order by
u.companyid desc limit 10

but to add that, i should return the date if available and return null value if date is not available..

how can i do this?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query