Link to home
Start Free TrialLog in
Avatar of tips54
tips54

asked on

sql condition using and

I'm about to loose my mind. I checking some data and i'm getting some output I don't think I should get.  Data look like:
Table1
ID :  AmtPaid:    Balance
1        200           0
2        200           10
Select ID from Table1 where ID =1 and (AmtPaid <>0 and Balance <>0)
The above statement does not return the data for ID 1. I was expecting output since i'm using And not OR. am I missing something.

thanks in advance.

ASKER CERTIFIED SOLUTION
Avatar of Chris Luttrell
Chris Luttrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey,

Have you tried the select statement:

Select ID from Table1 where ID = 1

that will get you the data in the Table where ID = 1

usually if you know the ID of the row you want - you do not need the rest of the statement, just the ID will get you the row you need.

Though,

If you want the row with the ID = 1, and other rows that conform to other parameters, you will need to do something like this:

Select ID, AmtPaid, Balance from Table1 where (ID = 1) OR (AmtPaid > 0 AND Balance > 0)

Or a statement like this:

Select * from Table1 where (ID = 1) OR (AmtPaid > 0 AND Balance > 0)

Give that a try.
Avatar of tips54
tips54

ASKER

that did... I'm just a big bird brain this evening.
Thank you
Thanks, but why only the B grade?  I strive to be an "A" student. :)