user5630104
user5630104

Reputation:

MySQL: Not to duplicate data

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.

Upvotes: 1

Views: 49

Answers (1)

Aycan Yaşıt
Aycan Yaşıt

Reputation: 2104

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

Upvotes: 1

Related Questions