Hello, I am trying to query several tables for output into 1 grid. The problem is that one of the "SELECT" is NOT always there. Not every workorder has a subcategory selected. When I run the following query, only the entries with ALL of the SELECT conditions as true will show up. How can I make it show ALL results? (IE: If a category/subcategory field is blank, show the workorder anyway)
CODE
SELECT wo.WORKORDERID AS 'ID',
u.FIRST_NAME AS 'Requester Name',
FROM_UNIXTIME(wo.CREATEDTIME/1000) AS 'Created Date',
wo.TITLE AS 'Subject',
cd.CATEGORYNAME AS 'Category',
scd.SUBCATEGORYID AS 'Sub Category'
from workorder wo,
aaauser u,
workorderstates wos,
categorydefinition cd,
subcategorydefinition scd
where
wo.requesterid=u.user_id
and wos.workorderid=wo.workorderid
and cd.categoryid=wos.categoryid
and scd.subcategoryid=wos.subcategoryid
ORDER BY wo.CREATEDTIME DESC;
I am including a picture of the database schema to help any of you further visualise why I am doing it this. Perhaps you can provide a completely different way as well!
Thank you!Edit: Adjusted code text to significantly better fit the small window
This post has been edited by SpeeDemon: 23 Jun, 2009 - 08:47 PM