View Full Version : Returning Rows That Don't have Inner Join


Bopo
12-03-2009, 04:58 AM
Hey guys

Basically I have the following query, it's untested due to no data at the moment, but it looks fine IMO. Anyway my question is, would it be possible to return R.Description (TblResource.Description) where there isn't a inner join, e.g. where there is no corresponding value in the TblRsrcType table, as in the oppsite of an inner join kinda.

Anyway here's my current query below, hopefully I've manage to explain my question.

SELECT R.Description
FROM TblResource R
INNER JOIN TblRsrcEmp RSE
ON R.ResourceCode = RSE.ResourceCode
WHERE R.ResourceType = 'Laptop'
AND RSE.Returned = 'Yes'

Vassago
12-03-2009, 02:27 PM
Hey guys

Basically I have the following query, it's untested due to no data at the moment, but it looks fine IMO. Anyway my question is, would it be possible to return R.Description (TblResource.Description) where there isn't a inner join, e.g. where there is no corresponding value in the TblRsrcType table, as in the oppsite of an inner join kinda.

Anyway here's my current query below, hopefully I've manage to explain my question.

SELECT R.Description
FROM TblResource R
INNER JOIN TblRsrcEmp RSE
ON R.ResourceCode = RSE.ResourceCode
WHERE R.ResourceType = 'Laptop'
AND RSE.Returned = 'Yes'

This should work, do a left join including all R.Description where RSE.ResourceCode is null, meaning, no match.

SELECT R.Description
FROM TblResource R
LEFT JOIN TblRsrcEmp RSE
ON R.ResourceCode = RSE.ResourceCode
WHERE R.ResourceType = 'Laptop'
AND RSE.Returned = 'Yes'
AND RSE.REsourceCode is null

Bopo
12-05-2009, 05:04 AM
Thanks for the query, I've tried it and used trial and error, but sadly I still can't get this working. It doesn't return records with the description 'Laptop' which are not in TblRsrcEmp. I've been racking my brain, thinking of maybe creating a view and select records that != the Laptop ID and still use the Returned = Yes,
but I think I'd still have the same problem.

Here's a print screen of the tables, note the query is using a different join / syntax since I've been trying numerous methods, hoping one would just work :).

http://i48.tinypic.com/w03pz4.png

SELECT R.Description
FROM TblResource AS R
INNER JOIN TblRsrcEmp AS RSE
ON R.ResourceCode = RSE.ResourceCode
WHERE (((R.ResourceType)= 'Laptop')
AND ((RSE.Returned)='Yes')
OR ((RSE.ResourceCode) Is Null));



Here's