A
A
Alexander M2018-10-25 14:41:17
MySQL
Alexander M, 2018-10-25 14:41:17

Duplicate data with multiple Left Join (Cartesian product), how to remove?

Hi all!
For the 2nd day I have been slowly approaching this request, but it still does not give in.
There is a request for obtaining data from 3 tables.
-Product -Characteristics
table 1 -Characteristics table
2

SELECT
  tx_carmodels.vendor as vendor,
  tx_carmodels.model as model,
  tx_carmodels.year as year,
  tx_carmodels.modification as modification,
tx_tyrespecifications.front_width as tyre_front_width,
tx_tyrespecifications.front_diameter as tyre_front_diameter,
tx_wheelspecifications.front_width as wheel_front_width,
tx_wheelspecifications.front_diameter as wheel_front_diameter
FROM
  tx_carmodels
LEFT JOIN tx_tyrespecifications ON tx_tyrespecifications.carmodel = tx_carmodels.id
LEFT JOIN tx_wheelspecifications ON tx_wheelspecifications.carmodel = tx_carmodels.id
WHERE
tx_carmodels.vendor_url = 'kia'
AND tx_carmodels.model_url = 'rio'
AND tx_carmodels.modification_url = '16i-jb'

accordingly, when outputting data, a Cartesian product is obtained.
What is the right solution to get data without duplicates with a minimum load on the database.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
idShura, 2018-10-25
@alexander7779

You do not have any duplicates, most likely in the tx_tyrespecifications and tx_wheelspecifications tables there is more than one characteristic for the selected model.

R
Rsa97, 2018-10-25
@Rsa97

Receive in separate requests. JOIN will give a Cartesian product anyway.

E
Eugene, 2018-10-25
@EpOsS

SELECT DISTINCT try it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question