0

I have created two tables and tried to join them, but it resulted in Query Error. What could be the problem?

Here is how I created tables

CREATE TABLE Customer
(
    "Ids" int,
    "Name" VARCHAR(100),
    "Gender" VARCHAR(100),
    "Age" int,
    "Phone" int
);

Insert Into Customer("Ids", "Name", "Gender", "Age", "Phone")
VALUES (1, 'Ruslan', 'Male', 14, 43214);
Insert Into Customer("Ids", "Name", "Gender", "Age", "Phone")
VALUES (2, 'Alex', 'Female', 19, 324323);
Insert Into Customer("Ids", "Name", "Gender", "Age", "Phone")


CREATE TABLE Product
(
    "Ids" int,
    "CustomerId" int,
    "ProductCode" VARCHAR(100),
    "Price" int
);

Insert Into Product("Ids", "CustomerId", "ProductCode", "Price")
VALUES (1, 1, 'Milk', 200);
Insert Into Product("Ids", "CustomerId", "ProductCode", "Price")
VALUES (2, 1, 'Butter', 105);
Insert Into Product("Ids", "CustomerId", "ProductCode", "Price")
VALUES (3, 1, 'Bread', 110);
Insert Into Product("Ids", "CustomerId", "ProductCode", "Price")

And Here is Query

SELECT Name, ProductCode FROM Customer 
INNER JOIN Product 
ON Customer.Name = Product.ProductCode
5
  • 1
    Remove the double quotes when creating the tables. It's creating the column names in a case-sensitive manner that doesn't serve much purpose in your case. Commented Jun 28, 2022 at 17:04
  • @TheImpaler I did it but it did not help Commented Jun 28, 2022 at 17:05
  • Works well without the double quotes. See dbfiddle.uk/… Commented Jun 28, 2022 at 17:07
  • As you started to use the dreaded double quotes you need to use them always - including any SELECT query. Commented Jun 28, 2022 at 17:12
  • Once beyond the syntax your query will not return any rows (at least the data provided). Your join predicate will always return False. You have no product name 'Alex' nor any customer named 'Milk'. Your predicate ON Customer.Name = Product.ProductCode should be ON Customer.Ids = Product.Customer_Id (once double quotes removed). Commented Jun 28, 2022 at 17:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.