I have 4 tables that I want to be joined.
Customers
Traffic
Average
Live
I want to insert joined data of these tables to "Details" table. The relationship between the tables is here: each of Traffic, Average and Live tables have a "cid" that is the primary key of "Customers" table:
Traffic.cid = Customers.id
Average.cid = Customers.id
Live.cid = Customers.id
The query that I wrote is here:
INSERT INTO Details
(
cid, Customer_Name, Router_Name,
Traffic_Received,
Average_Received,
Live_Received,
date
)
(
SELECT Customers.id AS cid, Customers.name AS Customer_Name, Traffic.Router_Name,
Traffic.Received,
Average.Received,
Live.Received,
Traffic.date
FROM Customers
INNER JOIN Traffic ON Customers.id=Traffic.cid
INNER JOIN Average ON Customers.id=Average.cid
INNER JOIN Live ON Customers.id=Live.cid
WHERE Traffic.date='2015-06-08'
)
But the result will have duplicated rows. I changed the JOIN
to both LEFT JOIN
, and RIGHT JOIN
. but the result does not changed.
What should I do to not have duplicated rows in Details
table?