Jump to content

Need to pull NOT from a table...


adrianle

Recommended Posts

Hi all-

I need some help figuring out a select query... I have a view made from two tables with a user ID as the common key. I need to retrieve all rows from the view where the email address is NOT equal to the session variable stated .

 

I built it using what I thought was a fairly simple query, and what it gives me back are any rows where the EMAIL field has a value (not equal to the session variable) which is fine.. but I ALSO need to get the other rows where the email field has NO value assigned to it currently.

 

How can I write this?

Link to comment
https://forums.phpfreaks.com/topic/217466-need-to-pull-not-from-a-table/
Share on other sites

So, I am guessing that "other rows where the email field has NO value " means that the value is a logical NULL instead of an empty string. Because using "<> $session_email" would return those records that have an empty string as the value. That would also occur if you were joining two tables and there was no matching record in the second table - in that case you just need to use the correct JOIN.

 

SELECT *
FROM table
WHERE email_address <> '$session_email'
   OR email_address IS NULL

 

If the problem has to do with JOINING two tables where there is no matching record in the second table, use a LEFT JOIN.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.