-1

im making a database for a college project in mysql workbench, as one of the requisitions my teacher asked to make it so that i can select the patients from a medical consultation that did the test for Covid19, currently my code to do it is like this:

SELECT Paciente FROM consulta WHERE Diagnostico='Covid19'

however this only shows the index numbers of said patients, i wanted a code that could show up the actual names and surnames on their tables, is there any way to do it?

Edit: sorry i didnt give this info initially, but the name and surname im trying to reach are on another table called "paciente" of which this "Paciente" above is a foreign key of

  • You definitely need to add some info about *structure* of your database – Vasily Liaskovsky Apr 03 '22 at 23:43
  • my mistake, basically there is a table called "paciente" where the data from the patients are, the name and surname im interested on showing, this "P:aciente" on the code above is a foreign key on the table "consulta" to that table – Davi Rafael Franke Apr 03 '22 at 23:46
  • If required data is in another table, you probably need a **join**. This site is a rich place when it comes to answers, help yourself to explore it. – Vasily Liaskovsky Apr 03 '22 at 23:50

1 Answers1

0

Your Paciente field probably only contains the ID. You should replace it to * to show every field and after that replace * with only the fields you want. In this case Name and Surname.

  • the name and surname are not on the consulta table, they are on the paciente table of which this paciente is an foreign key to, can i still call the name and surname by selecting from consulta? – Davi Rafael Franke Apr 03 '22 at 23:44
  • You will need to Join your consulta table and your paciente table in order to select your name and surname with the consulta table. – Zack Gingras Apr 03 '22 at 23:50