I have a database that has been populated with some data using create and insert into statements. I have written a SELECT statement that has a WHERE clause. The problem that I am encountering is that when I run the statement I have found that some of the data is repeating for what reason I don’t understand.
This the statement that I am trying to run.
SELECT Customer_Contact, Customer.CustomerID, Ord.OrderID,ItemOrdered.BeltLength,ItemOrdered.Colour,
ItemOrdered.Quantity,Design.DesignStyle
FROM Customer, Ord, ItemOrdered,Design
WHERE Customer.CustomerID = Ord.CustomerID
and Customer.Customer_Contact = 'John Daley'
and Design.DesignStyle ='Flat-Engraved';
The following link displays all the relevant code, that I have used for to create the above statement. [Database Code][1]
I have laid it out in the following format:
CREATE STATEMENT
INSERT INTO STATEMENT
Expanded Where clause and looks like the following:
SELECT Customer_Contact, Customer.CustomerID, Ord.OrderID,ItemOrdered.BeltLength,ItemOrdered.Colour,
ItemOrdered.Quantity,Design.DesignStyle
FROM Customer, Ord, ItemOrdered,Design
WHERE Customer.CustomerID = Ord.CustomerID and
ItemOrdered.OrderID = Ord.OrderID
and Customer.Customer_Contact = 'John Daley' and
Design.DesignStyle ='Flat-Engraved';
This works, however when I run the statement it brings up 3 records that are exactly the same.
SELECT Customer.Customer_Contact,
Customer.CustomerID,
Ord.OrderID,
ItemOrdered.BeltLength,
ItemOrdered.Colour,
ItemOrdered.Quantity,
Design.DesignStyle
FROM Customer,
Ord,
ItemOrdered,
BeltID
Design
WHERE Customer.CustomerID = Ord.CustomerID
AND Ord.OrderID = ItemOrdered.OrderID
AND Customer.Customer_Contact = 'John Daley'
AND Design.DesignStyle ='Flat-Engraved'
AND BeltID.DesignID = Design.DesignID;
The above statement is giving me an invalid identifier error, which I seem to not understand why?
It seems like you want to select something from the Design and ItemOrdered tables, but you are not including them in your join.
You probably need to expand your where-clause (with and-statements), where you link the ItemOrdered and Design tables to your Customer or Customer_Contract tables.