Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.