I have a query which is selecting tasks and inner joining to a customer table. I have now amended the application so that you can create a task without it being allocated to a customer. At the moment the join query will only return the record if the tasks.cid field is populated.
Can anyone suggest the best way to allow it to retrieve all tasks even if the cid field is null and if it is populated retrieve the customer details?
Regards
Leigh
SELECT Tasks.TaskId, Tasks.cId, Tasks.TaskDet, Tasks.startDate, Tasks.UsrId, WEEK(startDate) AS thisWeek, Customer.Company FROM tasks INNER JOIN Customer ON tasks.cid = Customer.cid
SELECT
Tasks.TaskId,
Tasks.cId,
Tasks.TaskDet,
Tasks.startDate,
Tasks.UsrId,
WEEK(startDate) AS thisWeek,
Customer.Company
FROM tasks
Left JOIN Customer
ON tasks.cid = Customer.cid
if cid is null it will retun numm for customer details
Pratima
if cid is null it will return null for customer details
Lmillard
ASKER
Thanks, left join was working and then i added some additional joins and it stopped retrieving the nulls again
SELECT Tasks.TaskId, Tasks.cId, Tasks.TaskDet, Tasks.startDate, Tasks.endDate, Tasks.DateCreated, Tasks.DateCompleted, Tasks.TaskStatus, Tasks.TaskType, Tasks.UsrId, WEEK(startDate) AS thisWeek, Customer.Company, Customer.Deleted, TaskTypes.TypeDesc, TaskStatus.StatusDesc, usr.usrName, usr.usrColour FROM tasks LEFT JOIN Customer ON tasks.cid = Customer.cid inner JOIN TaskTypes ON Tasks.TaskType = TaskTypes.TypeId inner JOIN TaskStatus ON Tasks.TaskStatus = TaskStatus.StatusId inner JOIN usr ON tasks.usrId = usr.usrId
SELECT
Tasks.TaskId,
Tasks.cId,
Tasks.TaskDet,
Tasks.startDate,
Tasks.UsrId,
WEEK(startDate) AS thisWeek,
Customer.Company
FROM tasks
Left JOIN Customer
ON tasks.cid = Customer.cid
if cid is null it will retun numm for customer details