SQL in DB MySQL

2

I have the following situation, a register with 5 fields being them: Type1, Type2, Type3, Type4 and value

The 4 type fields are combos fields, where you can select the all option, or any other option.

To exemplify:

<select class="form-control" id="tipo1" name="tipo1">
    <option value="" selected>TODOS</option>
    <option value="1">Opção 1</option>
    <option value="3">Opção 2</option>
    ...
</select>
<select class="form-control" id="tipo2" name="tipo2">
...

So far so good, it's working ok. In MySQL I have the following situation

Id  Tipo1  Tipo2  Tipo3  Tipo4  Valor
1   1      Null   2      3      100.00

Note:

  • The 4 types can not be null at the same time.
  • It may happen that type1, or type2 or type3 is populated, and all other types are null.
  • To contextualize, this is a goal register, which depending on the situation and value if it has been exceeded, should let pass, or block.

    I'm using PHP and MySQL, my problem is to make an appointment if the situation exists in the database, I can not see how to do this. I do not know if I could be clear, and maybe the answer is in front of me, but I already broke my head a lot and nothing came out, so I decided to ask for help. hehe.

        
    asked by anonymous 27.10.2016 / 03:51

    1 answer

    0
      

    My problem is to make an appointment if the situation exists in the bank

    Dude I understood the only situation that can not occur is if the four fields are null at the same time, any other is accepted. It seems that you did not validate this before because there would be no point in doing the consultation in the bank.

    The sql to check the cases in this 'wrong' situation would be:

    select id from tabela 
    where tipo1 is null 
    and tipo2 is null 
    and tipo3 is null 
    and tipo4 is null
    

    Remembering

    tipo1 is null (campo nulo)
    

    is an expression other than

    tipo1 = "" (string vazia)
    
        
    27.10.2016 / 22:35