MYSQL and condition

0

I need to make a select in my database as below:

select 
* 
from tbl_frete f 
join tbl_transportador t on f.idtransportador = t.idtransportador 
join tbl_cliente c on f.idcliente = c.idcliente 
join tbl_situacaofrete s on f.situacaofrete = s.idsituacao 
where f.idcliente = 1 
and f.situacaofrete = 0 
and f.situacaofrete = 1 
order by f.idfrete

but does not return anything, and when I do the select like this:

select 
* 
from tbl_frete f 
join tbl_transportador t on f.idtransportador = t.idtransportador 
join tbl_cliente c on f.idcliente = c.idcliente 
join tbl_situacaofrete s on f.situacaofrete = s.idsituacao 
where f.idcliente = 1  
order by f.idfrete

returns the data but not as I wanted it, since it does not return freights with situation 1

How do I do this AND?

    
asked by anonymous 08.11.2017 / 02:21

1 answer

2

John, as Leonardo said, puts you in the where condition of the record having two values at the same time, this will always return empty. Just take one of the conditions, or change the operator.

Removing one of the conditions:

select 
* 
from tbl_frete f 
join tbl_transportador t on f.idtransportador = t.idtransportador 
join tbl_cliente c on f.idcliente = c.idcliente 
join tbl_situacaofrete s on f.situacaofrete = s.idsituacao 
where f.idcliente = 1 
and f.situacaofrete = 1 
order by f.idfrete;

Changing the operator:

select 
* 
from tbl_frete f 
join tbl_transportador t on f.idtransportador = t.idtransportador 
join tbl_cliente c on f.idcliente = c.idcliente 
join tbl_situacaofrete s on f.situacaofrete = s.idsituacao 
where f.idcliente = 1 
and (f.situacaofrete = 0 
OR f.situacaofrete = 1) 
order by f.idfrete;

Or, use the in

select 
* 
from tbl_frete f 
join tbl_transportador t on f.idtransportador = t.idtransportador 
join tbl_cliente c on f.idcliente = c.idcliente 
join tbl_situacaofrete s on f.situacaofrete = s.idsituacao 
where f.idcliente = 1 
and f.situacaofrete in (0,1) 
order by f.idfrete;

Or, exclude the unwanted from the results:

select 
* 
from tbl_frete f 
join tbl_transportador t on f.idtransportador = t.idtransportador 
join tbl_cliente c on f.idcliente = c.idcliente 
join tbl_situacaofrete s on f.situacaofrete = s.idsituacao 
where f.idcliente = 1 
and f.situacaofrete != 2 
order by f.idfrete;
    
08.11.2017 / 02:43