I have one table registration
registration table
+------+------+
|ARIDNR|LIEFNR|
+------+------+
|1 |A |
+------+------+
|2 |B |
+------+------+
|3 |C |
+------+------+
UserLike Table
+------+------+
|ARIDNR|LIEFNR|
+------+------+
|A |B |
+------+------+
|B |A |
+------+------+
|A |C |
+------+------+
I would like to select join query with userlike table get those value return true when both user like each other
Example
User A is like User B Also User B is Like User A
so I get return true in User B response
in this case User A is like User C but User C is not Like User A in this case return false
I want output like below
Result
{
“username”:B
“match”:true
},
{
“username”:C
“match”:false
}
Assuming now duplicates, you can do:
select least(ARIDNR, LIEFNR), greatest(ARIDNR, LIEFNR)
from userlike
group by least(ARIDNR, LIEFNR), greatest(ARIDNR, LIEFNR)
having count(*) = 2;
Or, more efficiently (with the right indexes) as:
select ul.*
from userlike ul
where ul.ARIDNR < ul.LIEFNR and
exists (select 1
from userlike ul2
where ul2.ARIDNR = ul.LIEFNR and
ul2.LIEFNR = ul.ARIDNR
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.