PostgreSQL joined tables with null condition variable
I've a problem with my sql query in PostgreSQL while I'm trying to join a lot of tables. In section 'WHERE' I've a few conditions where I'm comparing some id values, e.g.
operator.agent_id = app.operator_id;
When every id ha开发者_运维问答s no null value, everything works, but in case even one id equals null, when query result is empty. Can I obtain such a result, that if one id equals null, then only values from this table are null, but rest is correct ?
To be more specific, I'm programming in Java, using EJB3:
stringQuery = "SELECT .... FROM ... WHERE...";
Query query = entityManager.createNativeQuery(stringQuery);
List<Object[]> objects = query.getResultList();
SELECT *
FROM app
LEFT JOIN
operator
ON operator.agent_id = app.operator_id
Move it to your join (left join) having the condition in your WHERE clause causes an inner join.
精彩评论