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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:46:56+00:00 2026-05-18T09:46:56+00:00

I have three tables: calls, attachments and notes and I want to display everything

  • 0

I have three tables: calls, attachments and notes and I want to display everything that’s in the calls table, but also display whether a call has attachments and whether the call has notes. – by determining if there is an attachment or note record with a call_id in it. There could be notes and attachments, or there may not be but I would need to know.

Tables structure:

calls:

call_id  |  title  |  description  

attachments:

attach_id  |  attach_name  |  call_id  

notes:

note_id  |  note_text  |  call_id  

If I write:

SELECT c.call_id
     , title
     , description
     , count(attach_id) 
FROM calls c 
LEFT JOIN attachments a ON c.call_id = a.call_id 
GROUP BY c.call_id
       , title
       , description

to give me a list of all calls and the number of attachments.

How can I also add in a column with the number of notes or a column which indicates that there is notes?

Any ideas?

Thanks.

  • 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-18T09:46:56+00:00Added an answer on May 18, 2026 at 9:46 am

    For the count

    SELECT 
         c.call_id, 
         title, 
         description, 
         count(DISTINCT attach_id) AS attachment_count , 
         count(DISTINCT note_id)  AS notes_count 
    FROM calls c 
    LEFT JOIN attachments a ON c.call_id = a.call_id 
    LEFT JOIN notes n ON n.call_id = c.call_id 
    GROUP BY c.call_id,title,description
    

    Or for existence (will be more efficient if this is all you need)

    SELECT 
         c.call_id, 
         title, 
         description, 
         count(attach_id) AS attachment_count , 
         case
            when exists (select * from notes n WHERE n.call_id = c.call_id) then
                cast(1 as bit)
            else
                cast(0 as bit)
        end as notes_exist
    FROM calls c 
    LEFT JOIN attachments a ON c.call_id = a.call_id 
    GROUP BY c.call_id,title,description
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: calls and attachments and I want to display everything that's
I have three tables, a user-table and two user-type tables. The user-type tables have
I have three tables as follows: table 1 is called Cat1, table 2 is
I have three tables in the many-to-many format. I.e, table A, B, and AB
I have three tables like that: Articles IdArticle Title Content Tags IdTag TagName ContentTag
I have three tables, we'll call them table1, table2, and table3. Lets say each
I have a list that is pulled from three tables, Department, Type and User.
I have these three tables, page table page_id page_title 1 a content table content_id
I have three tables. Let's call them a, b, and a_to_b. a_to_b contains (among
I have three existing SQL tables we will call teams, miles, and riders. Leaving

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.