I’ve got 3 tables linked together using foreign keys. One of the tables contains data that may be null, but I still want it displayed. I’ve also got multiple conditions worked in.
This is what I have so far, but it doesn’t work:
SELECT ord.OrdNo, ord.OrdDate, cu.CustNo, cu.CustFirstName, cu.CustLastName, em.EmpNo, em.EmpFirstName, em.EmpLastName
FROM OrderTbl ord, Customer cu, Employee em
WHERE cu.CustNo=ord.CustNo
AND em.EmpNo=ord.EmpNo (+)
AND ( OrdDate BETWEEN '01-Jan-04'
AND '31-Jan-04')
AND cu.CustState = 'CO'
Basically, the employee info might be null on the order table, but I still want the entries displayed. Any help would be appreciated, since I’ve only started learning SQL.
Edit: There were no errors in running this above query. It’s just that I was missing results that had null fields.
Pleaes use
JOINS, to be precise in your case LEFT JOIN to show all Employees’ orders:Reference:
Visual Representation of JOINs: