I have two tables that I need to join. These are:
art
id | art -------- 1 | A 2 | B 3 | C 4 | D 5 | E 6 | F 7 | G 8 | H 9 | I
and
Sess
artid | sessid -------------- 1 | 1 2 | 1 3 | 1 4 | 1 1 | 2 4 | 2 5 | 2 6 | 2 1 | 3 2 | 3 7 | 3 4 | 3
where Sess.artid
is a foregin key to art.id
.
From the tables above we can see that there are 3 sessions: A,B,C,D
, A,D,E,F
and A,B,G,D
.
I want to get a ranking of the arts that occur along with art A
. Something like:
D=3
B=2
How could I form such a query in mysql or postgres?