Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 21st Dec 2015, 05:06 PM   #1
Bananas are Yellow!
Registered Member
War Room Member
 
David Beroff's Avatar
 
Join Date: 2013
Location: Wyoming, PA, USA
Posts: 1,046
Thanks: 2,549
Thanked 1,600 Times in 928 Posts
Blog Entries: 4
Default
NULL's in MySQL logical AND operator precedence
Share on: 
fb share twitter share gplus share more share

I normally use an INNER JOIN between these two tables, but I have some specific needs for using the LEFT JOIN below. (I've stripped out most of the code, leaving just the essence below, so if you look at it, one's knee-jerk reaction would be "Why not just use INNER JOIN?"... except that you're not seeing the whole picture here.)

I reviewed the MySQL manual for logical operator precedence, but couldn't figure out for certain the right answer to this: In most languages, once it's determined that CompanyID is NULL, (because there's no corresponding Company row for that Member), the processor simply stops and immediately returns FALSE for the AND expression. i.e., there's no need to evaluate Company.Active. That's desirable, because if CompanyID is NULL, then Company.Active will be NULL, as it won't exist. I think I'm reading this to mean that MySQL will work in the exact same fashion, i.e., evaluate the AND as FALSE, not as NULL. So, that's what I would like to happen. Will it?

Code:
SELECT * FROM Member LEFT JOIN Company USING (CompanyID)
WHERE CompanyID IS NOT NULL AND Company.Active;
Thanks in advance!

Put MY voice on YOUR video: AwesomeAmericanAudio.com
David Beroff is offline  
Closed Thread


Bookmarks

Tags
logical, mysql, null, operator, precedence


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 04:02 PM.