SQL guru??
- Started
- Last post
- 9 Responses
- grafholic
i have SQL query question...it's pretty basic .
I need to find users in our database whose status is 0 and there's some value inserted into this thing called gid. If there's no value inserted, it's empty (we don't insert NaN or Null).
So, it's like
select * from [tablename] where status=0 AND gid null...??? or what do i do here?there are users like this in my database yet my query isn't finding single one of them, so i'm thinking the where clause around "gid" is wrong.
- sparker0
so leave it out? your simplest query would be:
select * from [table] where status='0';
or wildcard the results;
select * from [table] where status like '0%';
- grafholic0
no, i knbow status will be 0 so status=0.
but i'm also looking where gid value is empty.
how do i do that??
- gerbert0
AND WHERE (gid IS NULL)
- grafholic0
still not doing it...
The way I went around it is this statement:
select * from [tablename] where status=0 order by gid...that way users who has some value in gid will show up at the bottom of the result.
so there are at least 7 users (and now that i got the data, i'm fine), but statement:
select * from [tablename] where status=0 and gid IS NULL results in 0 records...
drives me crazy.
- sparker0
select * from [table] where gid='';
- trebor0
Try
select * from [tablename] where status=0 AND gid =''
select * from [tablename] where status=0 AND gid like ''
- trebor0
sorry, think it need to be like this
select * from [tablename] where status=0 AND where gid =''
- sparker0
'null' and 'empty' are different
- grafholic0
THANKS YOU GUYS.
high five to you all.that gave me the hint...it was actually:
select * from [tablename] where status=0 AND gid ''
hooray!!