I have 3 tables which I need to join.
Table
animal is the main table. It contains:
Code: |
LONG_ID | NAME | BREED_ID | BIRTH_DATE | FATHER_ID | KK
|
Table
fathers is table which contains data about father. It is related to table
animal by
FATHER_ID. It looks like that:
Code: |
FATHER_ID | LONG_ID | FATHER_NAME
|
Table
breed is table which contains data about breed. It is related to table
animal by
BREED_ID. It looks like that:
Code: |
BREED_ID | BREED_NAME | BREED_CODE
|
What I need is to display table which would look like that:
LONG ID(animal table) | NAME(animal table) | BREED NAME(breed table where BREED_ID = BREED_ID(from animal table)) | FATHER ID (animal table) | FATHER NAME (father table where FATHER_ID = FATHER_ID(from animal table)
For that I am using this sql query:
SELECT a.LONG_ID, a.NAME, b.BREED_NAME, a.FATHER_ID, f.FATHER_NAME
FROM animal a
LEFT JOIN breed b ON b.BREED_ID = a.BREED_ID
LEFT JOIN fathers f ON f.FATHER_ID = a.FATHER_ID;
And my table shows 3,064 entries but there are only 1,773 entries in
animal table. Many double entries appears in data table. Why? Is my sql query wrong?