SELECT FROM WHERE Clause

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

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

SELECT FROM WHERE Clause

Post by ianhull »

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

Re: SELECT FROM WHERE Clause

Post by santosj »

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 »

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 »

Which DBMS? MySQL? Postgres?
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

MySQL

Thanks
santosj
Forum Contributor
Posts: 157
Joined: Sat Apr 29, 2006 7:06 pm

Post by santosj »

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 »

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 »

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.
alex-weej
Forum Newbie
Posts: 19
Joined: Sun May 14, 2006 11:20 am

Post by alex-weej »

No
santosj
Forum Contributor
Posts: 157
Joined: Sat Apr 29, 2006 7:06 pm

Post by santosj »

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 »

courseowner != ''

this works great

thank you.
alex-weej
Forum Newbie
Posts: 19
Joined: Sun May 14, 2006 11:20 am

Post by alex-weej »

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 »

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 ''.
Post Reply