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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:51:33+00:00 2026-05-27T21:51:33+00:00

Here’s the question : I have 2 tables , one containing the base data

  • 0

Here’s the question :

I have 2 tables , one containing the base data and one containing data related to the base data with only one value so :

TABLE1
pKey | category1 | category2 | ..3 |etc

TABLE2
pKey | value1 |

Where pKey is unique to each real-world object, a serial number for example.

now, how would I compare the tables to match the values with the objects in the other table with the aim of adding the values of the objects to the “owner” of the objects ?

SCENARIO :

Obj1 is one of many franchises that one guy owns, at the end of the month we get a report stating the expenses/sales etc for all the franchises and all the owners of thereof of the brand and have to calculate how this particular owner did . So we compare the table2 to table1,to get the owner and add up the “nett profit” for this particular franchise to his running total at the end of the day hoping for data that looks like :

Table3
owner | Total Earnings |

I’ve written a query that does the compare :
SELECT * FROM Table1 INNER JOIN Table2 WHERE Table1.pkey = Table2.pKey

The only problem is that that, in itself, isn’t very useful. So is the following process the way of doing this, disregarding syntax errors and me forgetting to press shift all the time :

SELECT DISTINCT(Owner) FROM TABLE1

then loop through Table1 for each owner to get all his pKeys

SELECT pKey FROM Table1 Where Owner = ownerResult.Owner

then compare the results from that to TABLE2 to get the Values

SELECT Value FROM TABLE2 INNER JOIN TABLE1 WHERE table2.pKey = table1.pKey

then do the additions on that result.

Also, does SQL handle floating point numbers, if so are there any special steps I should be taking?

  • 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-27T21:51:34+00:00Added an answer on May 27, 2026 at 9:51 pm

    You can do this all in one statement:

    select
        t1.Owner,
        sum(t2.Value) as NetProfit
    from
        Table1 t1
        inner join Table2 t2 on
            t1.pKey = t2.pKey
    group by
        t1.Owner
    

    What we’re using here are called “aggregate functions.” In this case, it’s sum, but it could be max or min or avg or whatever. Furthermore, we can partition this by using the group by statement, to say, “I only want the aggregates to work at each distinct level of these columns.” In this case, owner.

    And to answer your last question, yes, it does. double, decimal, and numeric are all data types that can handle decimal numbers (there are quite a few more, too), but I need to know your type of database server (e.g.-MySQL, SQL Server, Oracle) to answer it more completely. Some even contain a money or currency data type, which ensures you don’t have partial cents and what have you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here we go again, the old argument still arises... Would we better have a
Here's the basic setup: I have a thin bar at the top of a
Here is my problem : I have a post controller with the action create.
Here is an example: I have the generic type called Account. I wish to
Here is my code...I have two dimensional matrices A,B. I want to develop the
here's what we have today: * NxM grid of points in 3D * we
Here is my code (Say we have a single button on the page that

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.