1

Heysa,

I have this little problem that im not quite good at mysql queries and i don't know proper terminology for this question so i'll just roll as i can :)

I have 2 rows in 1 table that i want to compare if they are not 0 and are equal. In php it would look something like this:

if(!empty($row1) && !empty($row2)){
   if($row1==$row2){
       return true;
   }else{
      return false;
   }
}else{
   return false;
}

Here is table if that's any help

id | b | t |
-----------
1 | 2 | 1 |
2 | 0 | 0 | 
3 | 1 | 1 |

And this:

SELECT * FROM table WHERE b=t

Returns also 0=0 record with id=2 ( that i don't want )

Correct query should return only record with id=3

1
  • What is your table structure? What columns are you using to link the rows? What has to be not 0? Commented Dec 2, 2010 at 1:09

1 Answer 1

3

SELECT * FROM table WHERE b = t AND b <> 0 AND t <> 0

Since we're testing that b = t, we know that if b <> 0 is true, then t <> 0 is also true. We can therefore shorten it to

SELECT * FROM table WHERE b = t AND b <> 0

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.