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 8134847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:11:46+00:00 2026-06-06T10:11:46+00:00

I have two tables in Sql Server, one containing IDs for files and the

  • 0

I have two tables in Sql Server, one containing IDs for files and the slides contained in those original files, and another for “sections” that can contain slides from one or more of the files, potentially in arbitrary order, duplicated, and/or with some slides eliminated.

Sample data looks like this:

FileSlide

FileID       SlideID
214          716
214          717
214          718
223          770
223          771
223          772
223          773
223          774
223          775

SectionSlide

SectionID    SlideID
527          716
527          718
527          717
527          770
527          773
527          774
527          775
527          774

I originally didn’t need a “SectionFile” relation, but now I do need that information to see which files were chosen for a particular section, regardless of slide details. My problem is examining the slide IDs between the SectionSlide and FileSlide tables to see whether there’s an overlap between the slides in any given File-Section pair. I would like to find all File-Section pairs that share slides.

For the sample data above, output would look like this:

SectionFileCandidates

SectionID    FileID
527          214
527          223

What is the query to produce this output?

Is it possible to calculate a metric that indicates what proportion of the original file’s slides exists in the section?

For the sample data above, output would look like this:

SectionFileCandidates

SectionID    FileID    Overlap
527          214       1.00
527          223       0.67

…that is, 3 out of 3 slides from file 214 are in section 527, and 4 out of 6 slides from file 223 are in section 527.

I was originally trying to compare groups of rows using the OVER (PARTITION BY ...) clause, but could not figure it out.

How can I do these two queries?

  • 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-06T10:11:47+00:00Added an answer on June 6, 2026 at 10:11 am

    Both queries are possible!


    First query:

    SELECT s.SectionID,
           f.FileID
    FROM SectionSlide s
    INNER JOIN FileSlide f ON s.SlideID = f.SlideID
    GROUP BY s.SectionID, f.FileID
    

    or

    SELECT DISTINCT s.SectionID,
                    f.FileID
    FROM SectionSlide s
    INNER JOIN FileSlide f ON s.SlideID = f.SlideID
    

    Second query:

    select s.SectionID, f.FileID,
           round(((count(distinct f.SlideID)*1.0) / aux.total), 2) as 'Overlap'
    from SectionSlide s
    inner join FileSlide f on f.SlideID = s.SlideID
    inner join (select f.FileID, count(f.SlideID) as 'total'
                from FileSlide f
                group by f.FileID) aux on aux.FileID = f.FileID
    group by f.FileID, s.SectionID, aux.total
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In SQL Server 2008 I have two tables. One table for users: id_user -
In SQL Server 2008: I have two tables, dtlScheme and dtlRenewal, with a one
I currently have two joined tables in a SQL Server database, one with news
In MS SQL Server I have two tables [Products] and [Product_img] with relationship (ONE
We have two tables in a SQL Server 2005 database, A and B.There is
Good Afternoon All, I have two tables in my SQL Server 2005 DB, Main
I have two SQL Server tables with Primary Keys (PK) and a Foreign Key
I have two identical SQL Server tables ( SOURCE and DESTINATION ) with lots
I have SQL Server 2008 Ent and OLTP database with two big tables. How
I have two SQL Server 2008 Enterprise databases (on two machines), and one of

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.