How to do these SQL requests?

1

I am developing a real estate portal but as it is the first time I do one, I do not know exactly how logic works to get the desired result. After tracing a path, I will still have to turn this into SQL requests.

As can be seen in the image, I have variants for TIPO , for DORMITORIOS , for AREA , for VAGAS , for VALOR , for BAIRROS , for CODIGO . p>

It does not exactly look for ready answers, I look for ideas on how to accomplish this task and I am open to increase information as per the doubts found.

Things I already know:

  • When typing a CODIGO all other fields will be disregarded ...
  • I think I can start filtering by VALOR , AREA ...

    
asked by anonymous 04.10.2014 / 01:32

1 answer

4

There is not much secret about how it should be done, the business rule of your screen is usually:

SE code is informed, you should ignore the other fields, then SELECT * FROM tabela WHERE codigo = 'codigo' , otherwise, every time a field comes with data, you add WHERE more, ex:

  • with bedroom type :

    SELECT * FROM imovel WHERE tipo_de_dormitorio = 'tipoDeDormitorio'
    
  • with dormitory type and dormitory numbers :

    SELECT * FROM imovel 
        WHERE tipo_de_dormitorio = 'tipoDeDormitorio' 
        AND numero_de_dormitorios = numeroDeDormitorios
    
  • with dormitory type, dormitory numbers and number of vacancies :

    SELECT * FROM imovel
        WHERE tipo_de_dormitorio = 'tipoDeDormitorio' 
        AND numero_de_dormitorios = numeroDeDormitorios 
        AND numero_de_vagas = numeroDeVagas
    

That's basically speaking, after you put normalization in your bank, you just need to put AND in the right places.

    
04.10.2014 / 01:49