Given 2 base tables, 1 table which stores the relation between them with a few extra attributes; taking a few extra attribute values as user input, based on that extracting relation from relation table.
This information has the ID of the main values (person and animal) not the names. I want to display the names on screen, like according to the input you gave the records which found are this person has this animal with him.
select DISTINCT table0.person_name, table5.animal_name
from table1
INNER JOIN table0, table5
on table1.person_id=table0.person_id
and
table1.animal_id=table5.animal_id
where table1.aa=input1
and table1.bb=input2
and table1.cc=input3
and table1.dd=input4
You have at least three errors.
WHEREclause should come after theJOIN .. ONclause, not before it.ON xxx AND ON yyy. Just writeON xxx AND yyy.Other points to consider:
input1, ..., input4come from?table0should be renamed toperson,table5toanimal, and table1 toperson_animalto make it easier to understand the purpose of each table.My best guess as to what you meant is this: