MySQL Forums
Forum List  »  Newbie

Query Assistance - Many to Many Join
Posted by: Leon Claassen
Date: October 18, 2016 11:58PM

Hi All,

I hope that I am posting this in the correct section. I need some help with creating a query. My current query seems to result in a many to many join, returning over 100,000,000 rows, instead of only 550 or so.

The scenario is as follows:
All the source data is populated into a master table, with multiple rows being created for each record.
The multiple rows is as a result of multiple questions being asked, and each question creates a new row in the master table.
Each record set is link by a record number.

My query looks like the below:
SELECT
SEG.record_number
, SEG.action_date
, SEG.location
, CASE
WHEN SEG.headers_question = 'Segmentation' THEN SEG.headers_value
END 'Segmentation'
, CASE
WHEN OUTL.headers_question = 'Address' THEN OUTL.headers_value
END 'Address'
, CASE
WHEN TOW.headers_question = 'AREA' THEN TOW.headers_value
END 'Area'
, CASE
WHEN GPS.headers_question = 'GPS coordinates' THEN GPS.headers_value
END 'GPS_Location'
FROM db.outletdata SEG
JOIN
db.outletdata OUTL
ON SEG.record_number = OUTL.record_number
JOIN
db.outletdata TOW
ON SEG.record_number = TOW.record_number
JOIN
db.outletdata GPS
ON SEG.record_number = GPS.record_number;

Your help / guidance will be highly appreciated.

Options: ReplyQuote


Subject
Written By
Posted
Query Assistance - Many to Many Join
October 18, 2016 11:58PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.