0

This query works perfectly and creates my temporary table with all the necessary columns, but I also want it to include rows when column 3 is NULL (currently it only gives me rows when column 3 has data in it).

  SELECT column1
        ,column2
        ,column3
        ,column4
        ,column5
  FROM Table1 
  INNER JOIN Table2
  ON table1.column3 = table2.column3

I have tried different statements such as AND, OR, which did not work. It is possible that I simply did not apply the statement correctly as I am a beginner. Whenever I try something it either gives me 0 rows or hundreds of thousands more than it should.

Your help is appreciated.

3 Answers 3

1

You could use a LEFT JOIN to return all rows from Table1, even when there isn't a match in Table2:

SELECT column1
    ,column2
    ,column3
    ,column4
    ,column5
FROM Table1 
LEFT JOIN Table2
ON table1.column3 = table2.column3
Sign up to request clarification or add additional context in comments.

Comments

1

This is an answer so short that it maybe should be a comment, but.....change your INNER JOIN with a LEFT JOIN

Comments

0

What you're looking for is a LEFT JOIN rather than your INNER JOIN:

  SELECT column1
        ,column2
        ,column3
        ,column4
        ,column5
  FROM Table1 
  LEFT JOIN Table2
  ON table1.column3 = table2.column3

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.