Hey it is kind of late to answer that but I got the same question, what I realized is that you must have a record with the ID of 0
in you second table to make this :
SELECT * FROM Y
INNER JOIN X ON ISNULL(Y.QID, 0) = ISNULL(X.QID, 0)
to happen, it actually says if there is none, then use 0
. BUT what if Y
table does NOT have a record with the ID of 0
?
So, I found this method, (and worked for my case):
SELECT
ISNULL(Y.QName, 'ThereIsNone') AS YTableQName
FROM
X
LEFT OUTER JOIN Y ON X.QID = Y.QID
A snapshot of my case
This way you DON'T need a record with 0
ID value in your second table (which is Y
in this case and Customers
in my case), OR any record at all
UPDATE:
You can also take a look at this post for better understanding.
ISNULL()
, so I'd assume SQL Server – NonalignmentX.QID = Y.QID
before theAND
? – EleonoreeleopteneISNULL
function; the syntax used here is usually spelledCOALESCE
. Then again, MySQL also has the<=>
operator, which won't help for this question. – ReplyISNULL()
is effectively byassing the index. This is a fairly novice query written poorly: Not hard to fix, but it just bit him. There is construct for this I've given both of them in my answer. – Scale