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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:56:55+00:00 2026-05-17T20:56:55+00:00

Two tables Table1 ID FileName 1 abc 2 abc 3 abc 4 xyz Table2

  • 0

Two tables

Table1

ID FileName

1  abc
2  abc
3  abc
4  xyz

Table2

ID Table1_ID isDeleted
1   1        1
2   2        1
3   3        0
4   4        0

I need to get the count of filename for the isDeleted=1 by passing any ID of table1, i.e for all the values(1,2,3) of ID, i need the count as 2

I tried with the following query

SELECT COUNT(t1.FileName) FROM Table1 t1 
LEFT OUTER JOIN Table1 t11 ON t1.FileName=t11.FileName 
INNER JOIN table2 t2 ON t2.Table1_ID =t1.ID AND t2.isDeleted=1
WHERE t1.ID=X; 

X-1,2,3

This always returns 3.

Edit: I need to get the count of the filename from the first table by passing the ID from the first table. The count should be based on the isdeleted column in second table. The tables are related by the column ID (table1) and Table1_ID (table2)

  • 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-17T20:56:55+00:00Added an answer on May 17, 2026 at 8:56 pm

    Give this a shot:

    select SUM(isDeleted)
    from Table2 
    where Table1_ID in (
      select ID from Table1
      where FileName = (select FileName
                        from Table1
                        where ID = 1)
    )
    

    Edit: to get file count:

    select count(*) 
    from Table1 a
    join Table2 b on a.ID = b.Table1_ID and b.isDeleted = 1
    where a.FileName = (select FileName
                       from Table1
                       where ID = 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database with two tables ( Table1 and Table2 ). They both
I'm using oracle(10). I've got two tables as follows: Table1 (uniq rows): ID AMOUNT
I have two tables with the following columns: table1: id, agent_name, ticket_id, category, date_logged
I've two tables: TableA and TableB, joined by TableA.TableA_Id->1..n<-TableB.TableA_Id. A simple PK-FK. I need
I have two similar tables which have data I need to display in a
I'm trying to get data from two MySQL tables, but having problems. Usually, I'd
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
I've got two tables: TableA ------ ID, Name TableB ------ ID, SomeColumn, TableA_ID (FK
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and
I have two tables: a source table and a target table. The target table

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.