Consider the following tables:
[Table: talks]
talkID | title | starred
-------+--------------+--------
1 | talk1-title | 1
2 | talk2-title | 1
3 | talk3-title | 0
4 | talk4-title | 0
5 | talk5-title | 0
[Table: talkspeaker]
talkID | speaker
-------+---------
1 | Speaker1
1 | Speaker2
2 | Speaker3
3 | Speaker4
3 | Speaker5
4 | Speaker6
5 | Speaker7
5 | Speaker8
[Table: similartalks]
talkID | similarTo
-------+----------
1 | 3
1 | 4
2 | 3
2 | 4
2 | 5
3 | 2
4 | 5
5 | 3
5 | 4
What I want to do is: Given the set of stellar conversations, I would like to select the top 2 non-stationary conversations (starred = 0) and their names and columns, which are most similar to the set of stellar conversations. The problem is that getting speakers requires the use of an aggregate function, and therefore you get the most similar conversations.
Without speakers in the battle, I was able to get the most similar conversations using the following query:
select t2.talkID, t2.title, count(*) as count
from similarTalks s, talks t1, talks t2
where s.talkID = t1.talkID
and t1.Starred = 1
and s.similarTo = t2.TalkID
and t2.Starred = 0
group by t2.title, t2.talkID
order by count desc
limit 2
As a rule, I use the following aggregate function to get speakers with the corresponding group by columns (suppose t = talkpeaker):
group_concat(t.speaker, ', ') as Speakers
how in
select t1.title, group_concat(t2.speaker, ', ') as Speakers
from talks t1, talkspeaker t2
where t1.talkID = t2.talkID
group by t1.title
. , , sqlite ( group_concat). , , , talkIDs 3 4.