Problem when extracting data from a weak entity with a foreign key in MySQL

0

I have a small problem when trying to extract all the data of a weak entity that I have created between a table called Doctor and another patient. When I do the query, I extract the data correctly but in triplicate, that is, instead of returning the information of:

Juan
Maria
Pedro

The query returns me:

Juan
Juan
Juan
Maria
Maria
Maria ...

This is the last attempt I've made so far.

SELECT * FROM Doctor_Account INNER JOIN Doctor_Patient_Connection ON Doctor_Patient_Connection.PatientAccount_ID=2;

With my query, what I want to return is, all the data of each of the doctors that are linked to the patient.

    
asked by Fulano 26.12.2018 в 14:39
source

1 answer

1

You have to add a common field between the 2 associated tables. Then in the WHERE add the condition. Example of how the structure of the SQL statement should be (fictitious data):

SELECT * FROM Doctor_Account INNER JOIN Doctor_Patient_Connection ON 
Doctor_Patient_Connection.PatientAccount_ID = Doctor_Account.id 
WHERE Doctor_Patient_Connection.PatientAccount_ID = 2;
    
answered by 26.12.2018 / 14:54
source