adrianle Posted November 1, 2010 Share Posted November 1, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/217466-need-to-pull-not-from-a-table/ Share on other sites More sharing options...
litebearer Posted November 1, 2010 Share Posted November 1, 2010 Show us what you have coded so far Quote Link to comment https://forums.phpfreaks.com/topic/217466-need-to-pull-not-from-a-table/#findComment-1129060 Share on other sites More sharing options...
rascle Posted November 1, 2010 Share Posted November 1, 2010 couldnt just use: WHERE email = "" ??? Quote Link to comment https://forums.phpfreaks.com/topic/217466-need-to-pull-not-from-a-table/#findComment-1129065 Share on other sites More sharing options...
Psycho Posted November 1, 2010 Share Posted November 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217466-need-to-pull-not-from-a-table/#findComment-1129066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.