var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Problem in connecting tables where foreign key is null
I want to display records from following two tables which are joined by OrderID.
ID, Name, OrderID
The SQL I am using to pull data is,
SELECT c.ID, c.Name, o.OrderID, o.OrderDate from Customer AS c, Order AS o WHERE c.OrderID = o.OrderID
But I need to display customers without Orders as well where the OrderID field in Customer table is NULL. How can I do this ?
Thanks in advance.
If you move to ANSI join syntax, you can then use a LEFT join to achive what you want.
Essentially this query says "Take all records from the customer table (the left one in the join) and where possible, find it a match in the orders table, based on the orderid field"
FROM Customer As c
JOIN Order As o
ON c.OrderID = o.OrderID
As a side note, your table designs look a tad flawed... Can one customer only make one order?
Thanks a lot for immediate reply and the solution.
Fixed the issue I was having then and there.