QUERY does not filter result correctly

1

I have the following query:

SELECT  pe.id_person , pa.id_person_patient , *  
FROM patient as pa INNER JOIN person as pe  on ( pa.id_person_patient = pe.id_person ) 
WHERE pe.elimination_date is null OR pe.elimination_date = 0  
AND pe.name = 'ALEJANDRA' 
GROUP by pa.id_person_patient

But the clause

AND pe.name = 'ALEJANDRA' 

Returns a result that is not valid. Why do I return a row with the name 'TEST' , if the clause says that it only looks for a name where it says 'alejandra' ?

    
asked by Gilberto Ibarra 31.07.2016 в 19:15
source

1 answer

2

I can not appreciate the complete result of the query but I assume it is because of a failure in grouping conditions in where for what should be:

SELECT  pe.id_person , pa.id_person_patient , *  
FROM patient as pa INNER JOIN person as pe  on ( pa.id_person_patient = pe.id_person ) 
WHERE (pe.elimination_date is null OR pe.elimination_date = 0) 
AND pe.name = 'ALEJANDRA' 
GROUP by pa.id_person_patient

This to ensure that the first two will be evaluated first and will be contrasted with the last one.

    
answered by 31.07.2016 / 20:24
source