开发者

PostgreSQL joined tables with null condition variable

开发者 https://www.devze.com 2023-01-22 16:43 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消