1

I have a MySQL statement that I want to use that will display the data in two different tables, but not have any duplicated data.

SELECT Customer.firstName, Customer.lastName, Purchase.productName, Purchase.productPrice
FROM Purchase
INNER JOIN Customer

This is currently the MySQL I am using and it does work, but it loads duplicated data which I do not want. I have looked around but not seeing a simple solution. Sorry in advance if it is a simple solution, been working for awhile and brain isn't really working.

1
  • When you use inner join, you should always have an on clause. Although MySQL makes it optional, you should always have one. Commented Dec 13, 2015 at 15:38

1 Answer 1

1

You have to bind those tables via related columns.

Let's assume primary column of table Customer is named ID and customer ID is being held in a column named customerID in table Purchase:

SELECT Customer.firstName, Customer.lastName, Purchase.productName, Purchase.productPrice
FROM Purchase
INNER JOIN Customer 
ON Custormer.ID=Purchase.customerID
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.