Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. how to create a sum query between multiple tables in Microsoft access

how to create a sum query between multiple tables in Microsoft access

Scheduled Pinned Locked Moved Database
databasetutorial
9 Posts 4 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10252606
    wrote on last edited by
    #1

    i have three tables: Table_provider Name_Provider Table_purchase ID_Purchase Date_Purchase Name_Provider Amount Table_payment ID_payment Date_payment Name_Provider Amount I want to get this resutl: Name_Provider Sum(Amount purchase) sum(Amount payement) thanks in advance:

    L M CHill60C 3 Replies Last reply
    0
    • U User 10252606

      i have three tables: Table_provider Name_Provider Table_purchase ID_Purchase Date_Purchase Name_Provider Amount Table_payment ID_payment Date_payment Name_Provider Amount I want to get this resutl: Name_Provider Sum(Amount purchase) sum(Amount payement) thanks in advance:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Member 10283191 wrote:

      I want to get this resutl:

      Try SQL. You're welcome.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

      U 1 Reply Last reply
      0
      • L Lost User

        Member 10283191 wrote:

        I want to get this resutl:

        Try SQL. You're welcome.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        U Offline
        U Offline
        User 10252606
        wrote on last edited by
        #3

        Im developping vb.net application with access database thats why i want this query

        L 1 Reply Last reply
        0
        • U User 10252606

          Im developping vb.net application with access database thats why i want this query

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I would love to help if you have a question, but you are ordering code.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

          1 Reply Last reply
          0
          • U User 10252606

            i have three tables: Table_provider Name_Provider Table_purchase ID_Purchase Date_Purchase Name_Provider Amount Table_payment ID_payment Date_payment Name_Provider Amount I want to get this resutl: Name_Provider Sum(Amount purchase) sum(Amount payement) thanks in advance:

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            Identify the primary/foreign keys, make the joins and create the query. If name_provider is your FK then you are screwed as that is an editable field. Get a book on SQL and that will explain the errors in that structure.

            Never underestimate the power of human stupidity RAH

            1 Reply Last reply
            0
            • U User 10252606

              i have three tables: Table_provider Name_Provider Table_purchase ID_Purchase Date_Purchase Name_Provider Amount Table_payment ID_payment Date_payment Name_Provider Amount I want to get this resutl: Name_Provider Sum(Amount purchase) sum(Amount payement) thanks in advance:

              CHill60C Offline
              CHill60C Offline
              CHill60
              wrote on last edited by
              #6

              As others have pointed out, that is a bad table schema. If you insist on having separate tables for purchase and payment then it should look like this:

              Table_provider
              ID_Provider
              Name_Provider

              Table_purchase
              ID_Purchase
              Date_Purchase
              ID_Provider
              Amount

              Table_payment
              ID_payment
              Date_payment
              ID_Provider
              Amount

              Personally I would have single transaction table with a transaction type column but each to their own. Whether you follow my advice or not, you will need to JOIN the tables based on the column that is common to all of them ID_Provider or Name_Provider if you leave things as they are. Here is an article that tells you how to do that Joining Tables in SQL[^] Note we are referring to "SQL" in the sense of T-SQL - the "language" and not SQL Server the database. As you are connecting from VB.NET to Access I presume you are using ADO or OLEDB - both of which will require SQL statements. Once you have worked out how to join your tables you already have the SELECT clause essentially written...

              SELECT Provider.Name_Provider. Sum(purchase.Amount), sum(Payment.Amount)

              Give it a go, but if you still get stuck reply to this message with the code that isn't working and we will try to help.

              M 1 Reply Last reply
              0
              • CHill60C CHill60

                As others have pointed out, that is a bad table schema. If you insist on having separate tables for purchase and payment then it should look like this:

                Table_provider
                ID_Provider
                Name_Provider

                Table_purchase
                ID_Purchase
                Date_Purchase
                ID_Provider
                Amount

                Table_payment
                ID_payment
                Date_payment
                ID_Provider
                Amount

                Personally I would have single transaction table with a transaction type column but each to their own. Whether you follow my advice or not, you will need to JOIN the tables based on the column that is common to all of them ID_Provider or Name_Provider if you leave things as they are. Here is an article that tells you how to do that Joining Tables in SQL[^] Note we are referring to "SQL" in the sense of T-SQL - the "language" and not SQL Server the database. As you are connecting from VB.NET to Access I presume you are using ADO or OLEDB - both of which will require SQL statements. Once you have worked out how to join your tables you already have the SELECT clause essentially written...

                SELECT Provider.Name_Provider. Sum(purchase.Amount), sum(Payment.Amount)

                Give it a go, but if you still get stuck reply to this message with the code that isn't working and we will try to help.

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #7

                CHill60 wrote:

                Personally I would have single transaction table with a transaction type column but each to their own

                This only works for a retail POS system where there is no credit supplied. As an invoicing exercise the link between purchase and payment is never designed as 1-1.

                Never underestimate the power of human stupidity RAH

                CHill60C 1 Reply Last reply
                0
                • M Mycroft Holmes

                  CHill60 wrote:

                  Personally I would have single transaction table with a transaction type column but each to their own

                  This only works for a retail POS system where there is no credit supplied. As an invoicing exercise the link between purchase and payment is never designed as 1-1.

                  Never underestimate the power of human stupidity RAH

                  CHill60C Offline
                  CHill60C Offline
                  CHill60
                  wrote on last edited by
                  #8

                  Quote:

                  As an invoicing exercise the link between purchase and payment is never designed as 1-1.

                  Good point, although I wasn't trying to suggest that sort of link between an invoice and a payment, just that in its simplest terms a transaction is money either positive or negative. Similar to Accounting Systems Model[^] Of course the OP doesn't have a column to indicate a credit transaction on the purchase table anyway. Or an Order table, or Invoice, or product .... :laugh:

                  M 1 Reply Last reply
                  0
                  • CHill60C CHill60

                    Quote:

                    As an invoicing exercise the link between purchase and payment is never designed as 1-1.

                    Good point, although I wasn't trying to suggest that sort of link between an invoice and a payment, just that in its simplest terms a transaction is money either positive or negative. Similar to Accounting Systems Model[^] Of course the OP doesn't have a column to indicate a credit transaction on the purchase table anyway. Or an Order table, or Invoice, or product .... :laugh:

                    M Offline
                    M Offline
                    Mycroft Holmes
                    wrote on last edited by
                    #9

                    I suspect the OP is either doing a training excercise or, Ghu forbid, writing something for a friend in need, one does not know retail and the other does not know software, fun times.

                    Never underestimate the power of human stupidity RAH

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups