I am trying to join three tables in MySQ, but when I do it my way, I get duplicate rows with incorrect values. and it appears that I am not doing it correctly.
I have three tables that I need to join:
nt_stentyper
id | tagsten | varenr_tilb | prod_type | dk | no | sv
nt_tunliste
varenummer | tunnummer | beskrivelse
nt_priser
varenummer | pris
The data I wish to find is grouped by the varenummer in nt_tunliste and nt_priser. That varenummer is taken for varenr_tilb.
I tried this:
SELECT * FROM nt_stentyper
INNER JOIN nt_tunliste ON nt_stentyper.varenr_tilb = nt_tunliste.varenummer
INNER JOIN nt_priser ON nt_stentyper.varenr_tilb = nt_tunliste.varenummer
WHERE nt_stentyper.tagsten = 1
ORDER BY nt_stentyper.prod_type ASC
… but that gives me duplicate rows like:
ID tagsten varenr_tilb prod_type dk no sv varenummer tunnummer beskrivelse varenummer pris_dk
1 1 12345678 1 1 1 1 12345678 12131415 RT 801 11111111 213
1 1 12345678 1 1 1 1 12345678 12131415 RT 801 12345678 200
5 1 11111111 5 1 1 1 11111111 11111112 Gratbånd 11111111 213
5 1 11111111 5 1 1 1 11111111 11111112 Gratbånd 12345678 200
… which isn’t what I want.
The query should only display one varenummer.
the condition on the second join should have something to do with
nt_priser, but it’s a duplicate of the first join condition.