Use of SELECT DISTINCT

Hi
I need to create JOIN of 3 tables. I use this scheme:

Table1.ID1is related to Table2.ID1
Table2.ID2 is related to Table3.ID2

avhd.weboggetti.IdProduct is related to avhd.fotolinks.IdArticolo
avhd.fotolinks.IdFoto is related to avhd.foto.ID

Then I need to filter result by avhd.weboggetti.IdProduct to see only one record (without duplicates). I'm trying to use SELECT DISTINCT, but it still visualize duplicate values.

How can I do this?
SELECT DISTINCT IdProduct,CustomT1Desc, CustomT2Desc, UM, Description,CustomT9Desc,IdArticoloMasterTagliaColore,
DescriptionExt1,PrezzoListinoUfficiale,ProdCode,QTotMagazzino,ProductMainCategoryAndFathers,IdFoto,Percorso,NomeFile
 
FROM avhd.weboggetti
 
LEFT JOIN (avhd.fotolinks LEFT JOIN avhd.foto ON avhd.fotolinks.IdFoto=avhd.foto.ID)
 
ON avhd.weboggetti.IdProduct=avhd.fotolinks.IdArticolo

Open in new window

DuplicateValues.png
minjakonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tigin44Commented:
try this

SELECT DISTINCT IdProduct,CustomT1Desc, CustomT2Desc, UM, Description,CustomT9Desc,IdArticoloMasterTagliaColore,
DescriptionExt1,PrezzoListinoUfficiale,ProdCode,QTotMagazzino,ProductMainCategoryAndFathers,IdFoto,Percorso,NomeFile
 
FROM avhd.weboggetti
      LEFT JOIN avhd.fotolinks ON avhd.weboggetti.IdProduct= avhd.fotolinks.IdArticolo
      LEFT JOIN avhd.foto ON avhd.fotolinks.IdFoto=avhd.foto.ID

but if your detail tables including more then 1 row per master relation thane this query results many rows..
0
kerwinsiyCommented:
hi did you check all the return fields, meaning all the columns requested, there could probably some item that makes them unique why distinct doesnt work properly

0
rpkhareCommented:
Check by adding:

Order By IDProduct Limit 1;
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

minjakonAuthor Commented:
Thanks to everybody, but It still gives me a duplicate values.
tigin44: In effect, my query returns me duplicate values, as same as yours.

kerwinsiy: I joine 3 tables and there is no fields with uniquw value

rpkhare: It renurns me only one row...
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please try this:
SELECT IdProduct,CustomT1Desc, CustomT2Desc, UM, Description,CustomT9Desc,IdArticoloMasterTagliaColore,
DescriptionExt1,PrezzoListinoUfficiale,ProdCode,QTotMagazzino,ProductMainCategoryAndFathers,IdFoto,Percorso,NomeFile
 
FROM avhd.weboggetti
 
LEFT JOIN (avhd.fotolinks LEFT JOIN avhd.foto ON avhd.fotolinks.IdFoto=avhd.foto.ID) 
ON avhd.weboggetti.IdProduct=avhd.fotolinks.IdArticolo
GROUP BY avhd.weboggetti.IdProduct 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
minjakonAuthor Commented:
Great, that is exactly what I was trying to do.
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.