How to do a query with different table conditions

2
  

REGISTRATION TABLE A        Attributes: Code, name, type
      TABLE NUMBER B
       Attributes: Code, number
      TABLE C PERSONNEL
       Attributes: Code, gender

I need to bring the name and type information from table A with corresponding numbers from table B by filtering by the attributes "type" from table A and "gender" from table C.

Here is my query:

select A.NOME, B.NUMERO
from A
left join B on
A.codigo = B.codigo
where
A.tipo=B and
C.genero='Homem'
    
asked by anonymous 01.05.2015 / 03:43

1 answer

2

The modeling needs to improve even, but from what I've seen code is primary and foreign key. Assuming this to be true, then it is necessary to include the PERSON table in the query to be able to search for a field of it. Your query might look like this:

SELECT c.nome, n.numero, p.genero
FROM cadastro c
LEFT JOIN numero n ON c.codigo = n.codigo
LEFT JOIN pessoa p ON c.codigo = p.codigo
WHERE c.tipo='sei la' and p.genero='Homem';
    
03.05.2015 / 01:36