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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:28:17+00:00 2026-05-15T01:28:17+00:00

I have two tables: a Files table, which includes the file type, and a

  • 0

I have two tables: a Files table, which includes the file type, and a File Properties table, which references the file table via a foreign key. Sample Files table:

| id | name  | type |
---------------------
|  1 | file1 | zip  |
|  2 | file2 | zip  |
|  3 | file3 | zip  |
|  4 | file4 | jpg  |

And the Properties table:

| file_id  | property |
-----------------------
|  1       |     x    |
|  2       |     x    |

I want to make a query, which shows the count of each file type, and how many files of that type have a property.

So in the example, the result would be

| type | filecount  | prop count |
----------------------------------
| zip  |    3       |     2      |
| jpg  |    1       |     0      |

I could accomplish this by

select f.type, (select count(id) from files where type = f.type), count(fp.id) from 
files as f, file_properties as fp where f.id = fp.file_id group by f.type;

But this seems very suboptimal and is very slow. Any better way to do this?

  • 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-05-15T01:28:18+00:00Added an answer on May 15, 2026 at 1:28 am
    select type, count(*) as filecount, sum(pc.count) as [prop count]
    from Files f
    left outer join (
        select file_id, count(*) as count
        from Properties p
        group by file_id
    ) pc on f.id = pc.file_id
    group by type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: Folder, Files. Each table has 4 fields: ParentID, ID, Name,
I have two tables document (id, file) similarity(id1,id2,similarityvalue) where id1 and id2 are foreign
I have two tables: Users and Files . Users table has 10 rows, Files
I'm using iTextSharp to generate some PDF files. I have two tables which have
There are two tables, which have a relationship(one-to-many). There are Meals table which contains
I have two tables in Sql Server, one containing IDs for files and the
In my dbsql file, I have two CREATE TABLES the first works and the
I have a database with two tables: data and file . file_id is a
I have two tables: table a ida valuea 1 a 2 b 3 c
Possible Duplicate: comparing contents of two files using python I have a file name

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.