Mysql Query Same Column Different Parameters

Asked

Viewed 232 times

0

Opa, simple thing, I have a test table, orgao and state

tables

teste = 'teste_estado_id_1'
        'teste_estado_id_2'
        'orgao_id'

orgao = 'orgao_id'

estado = 'estado_id' 

In a query you need to relate the test table to its two state columns with the state table and the orgao_id column with the organ table.

I tried so:

select
      *
from
    teste, estado, orgao
where
     estado.estado_id in(teste.teste_estado_id_1,teste.teste_estado_id_2) and
     orgao.orgao_id = teste.teste_orgao_id and
     teste.teste_ativo=1

Only I got back two records, and there should be only one.

Vlw

  • because the test table has 2 id table state fields?

  • Opa, are necessary in the test table to store two distinct items of the state table, are whole fields

  • already tried to break the in in 2 instructions?

  • Could you give me an example. vlw

  • estado.estado_id = teste.teste_estado_id_1 or estado.estado_id = teste.teste_estado_id_2

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.