Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9180043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:57:01+00:00 2026-06-17T17:57:01+00:00

Consider the following tables: [Table: talks] talkID | title | starred ——-+————–+——– 1 |

  • 0

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 starred talks, I would like to select the top 2 of the unstarred talks (starred = 0) and their titles and speakers that are most similar to the set of starred talks. The problem is that getting the speakers requires using an aggregate function, and so does getting the most similar talks.

Without the speakers in the fray, I have been able to get the most similar talks 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

Generally, I use the following aggregate function for getting the speakers, with appropriate group by columns (assume t = talkspeaker):

group_concat(t.speaker, ', ') as Speakers

as in

select t1.title, group_concat(t2.speaker, ', ') as Speakers 
from talks t1, talkspeaker t2
where t1.talkID = t2.talkID
group by t1.title

But I am not able to combine the two things together. It might matter that I am planning to run this query in a sqlite database (that is where the group_concat function comes from). The answer to the top 2 unstarred talks most similar to starred talks seem to be with talkIDs 3 and 4.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:57:02+00:00Added an answer on June 17, 2026 at 5:57 pm

    Firstly you might want to read this article about reasons to use ANSI 92 Joins instead of the aged ANSI 89 as used above. Secondly, SQLLite does support the GROUP_CONCAT function so you can use this.

    You just neeed to add your second query as subquery into the first to get the desired result:

    SELECT  Talks.TalkID, 
            Talks.Title, 
            ts.Speakers, 
            COUNT(*) AS SimilarTalks
    FROM    Talks
            INNER JOIN SimilarTalks 
                ON Talks.TalkID = SimilarTalks.SimilarTo
            INNER JOIN Talks t2
                ON SimilarTalks.TalkID = t2.TalkID
                AND t2.Starred = 1
            INNER JOIN
            (   SELECT  TalkID, GROUP_CONCAT(Speaker, ',') AS Speakers
                FROM    TalkSpeaker
                GROUP BY TalkID
            ) ts
                ON ts.TalkID = Talks.TalkID
    WHERE   Talks.Starred = 0
    GROUP BY Talks.TalkID, Talks.Title, ts.Speakers
    ORDER BY COUNT(*) DESC
    LIMIT 2;
    

    Example on SQL Fiddle

    EDIT

    You could also do this without a subquery using DISTINCT:

    SELECT  Talks.TalkID, 
            Talks.Title, 
            GROUP_CONCAT(DISTINCT ts.Speaker) AS Speakers,
            COUNT(DISTINCT t2.TalkID) AS SimilarTalks
    FROM    Talks
            INNER JOIN SimilarTalks 
                ON Talks.TalkID = SimilarTalks.SimilarTo
            INNER JOIN Talks t2
                ON SimilarTalks.TalkID = t2.TalkID
                AND t2.Starred = 1
            INNER JOIN TalkSpeaker ts
                ON ts.TalkID = Talks.TalkID
    WHERE   Talks.Starred = 0
    GROUP BY Talks.TalkID, Talks.Title
    ORDER BY COUNT(DISTINCT t2.TalkID) DESC
    LIMIT 2;
    

    However I see no benefit at all in this method, and it is likely to be less efficient (I have not tested so can’t be certain)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following database tables: Table messages with 13,000,000 rows (one row per message).
Consider the following tables: CREATE TABLE user_roles( pkey SERIAL PRIMARY KEY, bit_id BIGINT NOT
Please consider following tables. Table: Document docID, docNr, docScanTime 10, 99, 2012-08-02 11, 98,
Consider the following HTML tables: <table id=myTable1> <tr><td><input type=text id=quantity1 name=quantity1 /></td></tr> <tr><td><input type=text
Consider the following tables : drop table if exists testA; drop table if exists
Consider the following 2 tables: Table A: id event_time Table B id start_time end_time
Consider following tables: How to skip and take groups from the table? Tried using
Consider the following table which has the fields - id (int) and date_created (datetime):
Consider the following table.... hotel facilities 1 internet 1 swimming pool 1 wi-fi 1
Consider the following table tweets tweet_id call_id id_str timestamp text -------------------------------------------------- 1 11 12345

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.