Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Joining 3Tables gives duplicates rows in MySQL

i have 3 tables with 81 recrods and similar columns (just one got a column less then others) , here is an example :

enter image description here

when i join the 3 tables using a normal join or an inner join :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT DISTINCT *
FROM target 
INNER JOIN demons ON demons.Year  = target.Year
INNER JOIN violence ON violence.Year = target.Year;

i get duplicated rows like this :

enter image description here

they have the same Month and Year values I want to be able to join them without duplicates according to Year and Month

>Solution :

You would at least need to include a condition to match the month as well as the year:

SELECT *
FROM target 
INNER JOIN demons 
  ON demons.Year = target.Year AND demons.Month = target.Month
INNER JOIN violence 
  ON violence.Year = target.Year AND violence.Month = target.Month
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading