1

I have a very simple query, but somehow it fails, im pretty sure its just a syntax error, but I can find the error... Its very simular to this example below.. I want every that ONLY exists in TableA and not TableB or combined.

Select a.*
FROM TableA a
LEFT JOIN TableB b
ON a.key = b.key
WHERE b.key IS NULL
  • can you provide the error message you are receiving? – Gortonington Apr 11 '17 at 13:49
  • Im not getting any errors, it just turns up with 0 records, but I know thats not the correct answer. – Bidstrup Apr 11 '17 at 13:54
  • 2
    It was a logic issue then, not syntax - as you have shown in your answer below, changing the logic solved the issue. I believe the issue was from your WHERE statement, which required b.key to be null, which means it would only pull null values from TableA. – Gortonington Apr 11 '17 at 14:29
  • But this logic just works in all other normal mysql databases, so i thought i make was the b.key is null that need to be b.key = null or 'null' – Bidstrup Apr 11 '17 at 15:01
  • 1
    Could be. My statement above was just a quick guess. – Gortonington Apr 11 '17 at 15:30
1

I just found another solution what works.

select * 
from TableA 
where key not in (
  select key from TableB)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.