Prevent data from appearing in MYSQL search

2

I have a table consisting of the following columns, ID , Produto , Compra , Venda and Resultado .

I know the syntax for selecting the values I want, eg

Select * From tabela_exemplo where Produto = '030';

However, I would like to know if it is possible to add something like: Select all columns when Product is equal to 30, but from the result of this search, I do not want results to appear whose purchase is less than 0 .

That would be the idea, but I do not know how to apply it.

At1 I had expressed myself badly in the question, I think agr is easier to understand.

    
asked by anonymous 13.09.2017 / 15:30

3 answers

5
Select * From tabela_exemplo where Produto = '030' and Compra >= 0
    
13.09.2017 / 15:32
4

If you return the Products = 30 your own query returns that right.

Select * From tabela_exemplo where Produto = '030';

Now to filter the Products = 30 and Purchases > = 0, if this is the field of your table you would only need to use AND and the use of OPERATORS

 Select * From tabela_exemplo where Produto = '030' and Compra >= 0;
    
13.09.2017 / 15:46
3

Dude, in this case you need to report two conditions on WHERE of your SELECT :

 SELECT * FROM  tabela_exemplo WHERE Produto = '030' AND Compra >= 0;
  

The AND, OR and NOT operators

     

The WHERE clause can be combined with AND, OR and NOT operators.

     

the AND and OR operators are used to filter records based on   more than one condition:

     

The AND operator displays a record if all conditions separated by   AND are TRUE.

     

The OR operator displays a record if any of the conditions   separated by OR is TRUE.

     

The NOT operator displays a record if the condition (s)   TRUE (S).

    
13.09.2017 / 16:02