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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:20:18+00:00 2026-05-21T19:20:18+00:00

I am a novice at this, nor is this my data. We are trying

  • 0

I am a novice at this, nor is this my data. We are trying to pull multiple records into one record for query results.

To simplify the tables and amount of data, the following two tables should be sufficient:

Table 1

PRVDR_NUM | RPT_REC_NUM  
013          1234
014          4567

Table 2

RPT_REC_NUM |  WKSHT_CD | LINE_NUM | ITM_VAL_NUM
1234             f1         3           30
1234             f1         9           3
1234             e2       100           100
4567             f1         3           20
4567             f1         9           8
4567             e2       100           100

The first part is to get all records where the ITM_NUM_CAL is between 25 and 50 for WKSHT_CD f1 and LINE_NUM 3, that ITM_NUM_VAL is revenue.

SELECT      r.PRVDR_NUM as Provider, 
            r.RPT_REC_NUM as 'Report Record', 
            n.ITM_VAL_NUM as Revenue

FROM        Table 1 r
        left outer join Table 2 n on 
        r.RPT_REC_NUM = n.RPT_REC_NUM

WHERE (n.WKSHT_CD = 'f1') and (n.LINE_NUM = '3')
        and (n.ITM_VAL_NUM > 25) and (n.ITM_VAL_NUM < 50)
        and left(r.PRVDR_NUM, 2) in ('01','04','11','18','25','26','34','44','49')

So our results are:

Provider |  Report Record | Revenue 
 013           1234         30    

But we also want to be able to pull the corresponding ITM_VAL_NUM for WKSHT_CD f1 and LINE_NUM 9, which we’ll call cost.

So the results should be:

Provider |  Report Record | Revenue | Cost
 013           1234          30         3

Much thanks in advance.

EDIT

I believe this is the final query I was looking for after some maneuvering and the addition of a new variable, CLMN_NUM, which is another column in table2.

SELECT r.PRVDR_NUM as Provider, 
       r.RPT_REC_NUM as 'Report Record', 
       n.ITM_VAL_NUM as Revenue,
       n2.ITM_VAL_NUM as 'Cost',
       n3.ITM_VAL_NUM as 'Visits'

FROM table1 r
    LEFT OUTER JOIN table2 n on r.RPT_REC_NUM = n.RPT_REC_NUM
    LEFT OUTER JOIN table2 n2 on n.WKSHT_CD = n2.WKSHT_CD
    and n.RPT_REC_NUM = n2.RPT_REC_NUM and n2.LINE_NUM = 9
    LEFT OUTER JOIN table2 n3 on r.RPT_REC_NUM = n3.RPT_REC_NUM 
    and n3.WKSHT_CD = 'e2' and n3.LINE_NUM = 100 and n3.CLMN_NUM = xxxx  

WHERE (n.WKSHT_CD = 'f1') 
AND (n.LINE_NUM = '3')
AND (n.ITM_VAL_NUM > 25) 
AND (n.ITM_VAL_NUM < 50)
AND left(r.PRVDR_NUM, 2) in ('01','04','11','18','25','26','34','44','49')
  • 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-21T19:20:18+00:00Added an answer on May 21, 2026 at 7:20 pm

    A couple ways:

    Subquery

    SELECT r.PRVDR_NUM as Provider, 
           r.RPT_REC_NUM as 'Report Record', 
           n.ITM_VAL_NUM as Revenue
           (SELECT ITM_VAL_NUM 
            FROM Table2 
            WHERE WKSHT_CD = n.WKSHT_CD 
            AND LINE_NUM = 9) AS Cost
    FROM Table1 r
        LEFT OUTER JOIN Table2 n on r.RPT_REC_NUM = n.RPT_REC_NUM
    WHERE (n.WKSHT_CD = 'f1') 
    AND (n.LINE_NUM = '3')
    AND (n.ITM_VAL_NUM > 25) 
    AND (n.ITM_VAL_NUM < 50)
    AND left(r.PRVDR_NUM, 2) in ('01','04','11','18','25','26','34','44','49')
    

    Another JOIN

    SELECT r.PRVDR_NUM as Provider, 
           r.RPT_REC_NUM as 'Report Record', 
           n.ITM_VAL_NUM as Revenue
           n2.Cost
    FROM Table1 r
        LEFT OUTER JOIN Table2 n on r.RPT_REC_NUM = n.RPT_REC_NUM
        LEFT OUTER JOIN Table2 n2 on n.WKSHT_CD = n2.WKSHT_CD
            AND LINE_NUM = 9
    WHERE (n.WKSHT_CD = 'f1') 
    AND (n.LINE_NUM = '3')
    AND (n.ITM_VAL_NUM > 25) 
    AND (n.ITM_VAL_NUM < 50)
    AND left(r.PRVDR_NUM, 2) in ('01','04','11','18','25','26','34','44','49')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I don't consider myself a novice at MySQL but this one has me
I'm a novice programmer and I'm trying to learn Android coding using Eclipse. This
Currently I am trying to clone this git repo: https://github.com/twilio/OpenVBX into my main repo,
I am attempting to query the twitter search engine (search.twitter.com), convert the results into
So, to preface, I'm a complete novice at this Excel business. I've found similar
This is a really novice question, but I don't write C unless (err, if)
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
I'm a novice in XSLT and I'm struggling a lot with this issue: I
I'm a novice when it comes to sql so forgive me if this seems
I'm a PHP novice, and I recently found this database-free pagination script on a

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.