1

I have 2 tables:

  1. req_docs

req_docs

and pers_docs

enter image description here

My sql query:

SELECT *
FROM req_docs
LEFT OUTER JOIN pers_docs ON req_docs.doc_nid = pers_docs.doc_nid
WHERE req_docs.pos_id ="CPT"
  AND pers_docs.pers_nid = 6
  AND pers_docs.expires <= "2009-09-01"`

It returns only 2 rows. Which is ok, but I need also return not existing matches from pers_docs join as NULL values. Help please!

1 Answer 1

2

When LEFT JOIN, put the right side table's conditions in the ON clause to get true left join behavior! (When in WHERE, you get regular INNER JOIN result.)

SELECT *
FROM req_docs
LEFT OUTER JOIN pers_docs ON req_docs.doc_nid = pers_docs.doc_nid
                          AND pers_docs.pers_nid = 6
                          AND pers_docs.expires <= "2009-09-01"
WHERE req_docs.pos_id = "CPT"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.