Click here to Skip to main content
15,559,491 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have two table first is item master table(Icode,ItemName,UOM) and second customer item tabel(CICode,CItemName,UOM,CustomerID,Icode), Now i want when i define customer in second talbe then second table item is display, if do not mentioned in second table then item pick from first table.

What I have tried:

select ItemMasterFile.Descriptionitem,Customeritem.Citem ,customeritem.CIname,Customer.CustomerName
from ItemMasterFile left Join customeritem on ItemMasterFile.CodeItem=customeritem.Citem
left join Customer on Customer.CustomerID=Customeritem.CustomerID


if Customer exist 
   join with Customeritem 
else 
  Join with ItemMasterFile
Posted
Updated 22-Apr-19 3:28am
v2

1 solution

Take a look a the LEFT JOIN example here: SQL LEFT JOIN Keyword[^]
In your case the query should look like this:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
WHERE OrderID IS NOT NULL
ORDER BY Customers.CustomerName;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900