1
I have the following two tables as shown in the following image:
I wanted for example comparing the username
(session level of each user) remove their id. I have used the following query
but it doesn’t work SELECT id_medico FROM medico UNION SELECT id_paciente FROM paciente WHERE username=%s
. The %s comes from pyhton
, since I’m using the query
on a page with backend
in pyhton
. To query
complete is this: (SELECT id_medico FROM medico WHERE username=%s UNION SELECT id_paciente FROM paciente WHERE username=%s,(username,username))
.
So far the id returned is always the same, 1.
P.S.:I’m using the pymysql
and Flask
.
What you want is when
username
forpaciente1
, return the id 1 of the table patients, if it’spaciente2
, return the value 2, but ifmedico1
, return the id 1 of the table doctors?– Woss
@Andersoncarloswoss exactly that
– Adriano Maia
See http://sqlfiddle.com/#! 9/b6c1f/1. Thus ids are returned correctly. I used the ids 7 and 8 for doctors to make sure they are not returning wrong. The only thing is that so it is not possible to know which of the tables the id is coming. You will need to know if you are a patient or a doctor?
– Woss
@Andersoncarloswoss this way for what I wanted is already working and I thank you. But for the future I needed to know, is it possible ?
– Adriano Maia
Yes. It is possible. See answer.
– Woss