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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:18:07+00:00 2026-06-13T07:18:07+00:00

Not sure the title explains the problem well; this is what I’m working with,

  • 0

Not sure the title explains the problem well; this is what I’m working with,

I have the following tables,

-- table = kms_doc_ref_currnt_v
DOC_ID    VARCHAR2(19)
TO_DOC_ID    VARCHAR2(19)
BRANCH_ID    NUMBER(8)
REF_TYP_CD    VARCHAR2(20)

-- table = kms_fil_nm_t
DOC_ID    VARCHAR2(19)    PRIMARY KEY    UNIQUE

For example, I can get a count of all kms_doc_ref_currnt_v records that have a to_doc_id = 59678, where 59678 is one value in kms_fil_nm_t, with this query,

select 'doc_id 59678 has ' || count(to_doc_id) as cnt from kms_doc_ref_currnt_v where branch_id=1 and ref_typ_cd in ('CONREF', 'KBA') and to_doc_id=59678;

kms_doc_ref_currnt_v.to_doc_id is a field that has one of the kms_fil_nm_t.doc_id values. kms_doc_ref_currnt_v.doc_id is also one of the values in kms_fil_nm_t.

The single query I’m looking for would loop over each kms_fil_nm_t.doc_id and count all the rows in kms_doc_ref_currnt_v that have a similar to_doc_id. Each row returned would look like the output of the query above. Here’s example output,

doc_id 1 has 32
doc_id 2 has 314
doc_id 3 has 2718
doc_id 4 has 42
doc_id 5 has 128
doc_id 6 has 11235
.
.
.

Probably simple but I just can’t figure it out.

  • 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-13T07:18:08+00:00Added an answer on June 13, 2026 at 7:18 am

    Do a join with two tables and add a GROUP BY clause as below:

        SELECT 'doc_id 59678 has ' || count(to_doc_id) as cnt 
        FROM kms_doc_ref_currnt_v kv, kms_fil_nm_t kt
        WHERE kt.doc_id= kv.to_doc_id 
              AND kv.branch_id=1 
              AND kv.ref_typ_cd in ('CONREF', 'KBA') 
              AND kv.to_doc_id=59678
        GROUP BY kv.to_doc_id;     
    

    EDIT:

    To get all records from kms_doc_ref_currnt_v irrespective of their reference availability in kms_fil_nm_t and kv.to_doc_id=59678, do like this:

        SELECT 'doc_id 59678 has ' || count(to_doc_id) as cnt 
        FROM kms_doc_ref_currnt_v kv 
             LEFT JOIN kms_fil_nm_t kt
             ON (kt.doc_id= kv.to_doc_id )
        WHERE  kv.branch_id=1 
              AND kv.ref_typ_cd in ('CONREF', 'KBA') 
        GROUP BY kv.to_doc_id; 
    

    to replace the hardcoding 59678, you may want to write:

        SELECT 'doc_id ' || kt.doc_id || ` has ' || count(to_doc_id) as cnt 
        FROM kms_doc_ref_currnt_v kv 
             LEFT JOIN kms_fil_nm_t kt
             ON (kt.doc_id= kv.to_doc_id )
        WHERE  kv.branch_id=1 
              AND kv.ref_typ_cd in ('CONREF', 'KBA') 
        GROUP BY kv.to_doc_id, kt.doc_id; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(not sure if title explains the matter well enough) I have this piece of
I'm not sure if the title explain the real problem. I have a shell
I am not sure whether the title clearly explains my problem, will try to
Sorry for the horrible title, not sure how to explain this. I have a
I'm not sure the title explains it well enough, but was trying to keep
I'm not sure how to explain this problem so the title is kind of
Not sure if my title explains it very well so here's an example. I
The title might not explain my problem fully but I wasn't sure how to
Not sure the title fully describes the problem/question I'm trying to ask, sorry. One
I'm not sure that title is worded very well, but not sure how else

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.