SQL Query - PgSQL
Have a sql query to construct. Seems pretty basic and I don't seem to be able to wrap my head around it. There are two tables something like this:
Table A : call_id receive_id Table B : entity_id parent
------- ---------- --------- ------
x y x a
y z y b
p z z b
p c
The elements in both call_id column and receive_id column are of type entity. Table B holds the parents for each entity.
Try this(having been verified on my MySQL):
select a.* from
A a inner join B b1 on a.call_id=b1.entity_id
inner join B b2 on a.receive_id=b2.entity_id
where b1.parent<>b2.parent
SELECT *
FROM A
WHERE (SELECT B.parent FROM B WHERE B.entity_id = A.call_id)
!= (SELECT B.parent FROM B WHERE B.entity_id = A.receive_id)
;
加载中,请稍侯......
精彩评论