Prevent data from appearing in MYSQL search

Asked

Viewed 111 times

2

I have a table composed by the following columns, ID, Produto, Compra, Venda and Resultado.

I know the syntax to select the values I want, Example:

Select * From tabela_exemplo where Produto = '030';

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

That would be the idea, but I don’t know how to apply.

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

  • If the product and purchase are less than 0, then you do not want to select all columns ?

  • I expressed myself badly in the question, in vdd, I would like it to search all products equal to 30, and from this search do not appear the values of the Purchase column that are less than 0.

  • Can you edit the question.

3 answers

5


Select * From tabela_exemplo where Produto = '030' and Compra >= 0
  • 1

    Shouldn’t be Compra >= 0? For the question says except when, that is, records that have Compra < 0 should not be included.

  • I edited the answer, and analyzing better, I think that neither of the two is right... The OP says "except when product and purchase are less than zero". Is confused.

  • I really typed wrong there, ignore the product, it would be: "except when the purchases are less than q 0." I think I expressed myself badly in the question, in vdd, I want him to look for all products equal to 030, and from this search, do not appear below 0

  • Then you’re right :D

  • I re-edited the question, I think agr became clear

  • It is right the query I put, you tested? If you have solved your problem can mark it as correct in the "V" next.

Show 1 more comment

4

If you return the Products = 30 your own query returns it 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 just use the AND and the use of OPERATORS

 Select * From tabela_exemplo where Produto = '030' and Compra >= 0;

3

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

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

Operators AND, OR and NOT

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

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

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

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

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

Browser other questions tagged

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