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
  • 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. – The Impaler Jun 28 '22 at 17:04
  • @TheImpaler I did it but it did not help – Ruslan Pylypyuk Jun 28 '22 at 17:05
  • Works well without the double quotes. See https://dbfiddle.uk/?rdbms=postgres_14&fiddle=e8cc0c9945ea8b5bd88d64460ad5a176 – The Impaler Jun 28 '22 at 17:07
  • As you started to use the dreaded double quotes you need to use them **always** - including any SELECT query. –  Jun 28 '22 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). – Belayer Jun 28 '22 at 17:20

0 Answers0