Search code examples
mysqlsqlnullforeign-keysinner-join

inner join two tables having null values on the foreign keys of each other


I have the following data in the database in table1

enter image description here

I run the following query and returns nothing

SELECT
  someColumns

  FROM table1

  INNER JOIN table2 ON table1.id = table2.id
  INNER JOIN table3 ON table1.anotherId = table3.anotherId 

I want to return all the records in (table2 with id = table1.id and table3 with anotherId = table1.anotherId)


Solution

  • You should using LEFT OUTER JOIN to get the specified result.