PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Mon May 15, 2006 1:56 pm
Hi guys,
I need to select all the records in a table using the WHERE clause
but my problem is I need to select everything WHERE courseowner is not null or empty
Please help.
Thanks
santosj
Forum Contributor
Posts: 157 Joined: Sat Apr 29, 2006 7:06 pm
Post
by santosj » Mon May 15, 2006 2:14 pm
SQL is mostly a language construct.
Code: Select all
WHERE courseowner NOT NULL OR courseowner = ''
I would check the 'NOT NULL' text, you may have to use
Code: Select all
courseowner = NULL OR courseowner = ''
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Mon May 15, 2006 2:31 pm
Thanks for this,
I have just tried it with no luck.
Any other suggestion very welcome.
thanks
alex-weej
Forum Newbie
Posts: 19 Joined: Sun May 14, 2006 11:20 am
Post
by alex-weej » Mon May 15, 2006 2:36 pm
Which DBMS? MySQL? Postgres?
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Mon May 15, 2006 2:37 pm
MySQL
Thanks
santosj
Forum Contributor
Posts: 157 Joined: Sat Apr 29, 2006 7:06 pm
Post
by santosj » Mon May 15, 2006 2:39 pm
Code: Select all
courseowner != NULL OR courseowner != ''
alex-weej
Forum Newbie
Posts: 19 Joined: Sun May 14, 2006 11:20 am
Post
by alex-weej » Mon May 15, 2006 2:41 pm
Code: Select all
WHERE courseowner IS NOT NULL
AND courseowner != ''
"IS NOT NULL" is what you need.
santosj
Forum Contributor
Posts: 157 Joined: Sat Apr 29, 2006 7:06 pm
Post
by santosj » Mon May 15, 2006 2:42 pm
AND should be OR perhaps?
Unless to Mysql NULL and empty are the same thing, from my experience, if NULL, NULL would be in the field and if empty it would be used for NOT NULL fields.
Last edited by
santosj on Mon May 15, 2006 2:43 pm, edited 1 time in total.
santosj
Forum Contributor
Posts: 157 Joined: Sat Apr 29, 2006 7:06 pm
Post
by santosj » Mon May 15, 2006 2:45 pm
Okay, yeah, I see your point, I have a difficult time with logic.
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Mon May 15, 2006 2:45 pm
courseowner != ''
this works great
thank you.
alex-weej
Forum Newbie
Posts: 19 Joined: Sun May 14, 2006 11:20 am
Post
by alex-weej » Mon May 15, 2006 2:46 pm
He phrased it "where courseowner is not null or empty"
Boolean logic converts that to "where courseowner is not null and courseowner is not empty".
alex-weej
Forum Newbie
Posts: 19 Joined: Sun May 14, 2006 11:20 am
Post
by alex-weej » Mon May 15, 2006 2:47 pm
Ian, please include the check for "courseowner IS NOT NULL" because NULL is not the same as ''. If you have an actual NULL value in your database it won't match ''.