Results 1 to 4 of 4

Thread: Subtraction between two SQL tables

  1. #1
    Join Date
    Aug 2009
    Posts
    57

    Subtraction between two SQL tables

    I search the net and no answers or a few that I find, but unfortunately not good at all. I explain my problem,
    Table 1 => mark, libel, model, series, qty

    Table 2 => mark, libel, model, series, qty

    to display the number of product group is followed by model:

    Code:
    SELECT make, model, libel, series, SUM (qty) AS qty 
    FROM TABLE 1 
    GROUP BY model;
    and what I want to do is subtraction of my table 1 with my table 2. Basically if I find the same product in my table 2, I want in my table 1 it is automatically removed. I hope that my explanation was clear and optimum.

  2. #2
    Join Date
    Nov 2008
    Posts
    1,185

    Re: Subtraction between two SQL tables

    I hope that the tables do not actually have these names!
    - TABLE is an SQL reserved word.
    - A table name with a space is a source of misunderstanding and error for the DBMS.

    Turning now to the problem ...

    what I want to do is subtraction of my table 1 with my table 2. Basically if I find the same product in my table 2, I want in my table 1 it is automatically removed.
    Would you say:
    1) What you want to also count how many vehicles of each model in Table 2 can do arithmetic subtraction of two numbers for each model?
    2) What you want to remove from the table 1 the rows for the existing models in Table 1?

  3. #3
    Join Date
    Aug 2009
    Posts
    57

    Re: Subtraction between two SQL tables

    My tables are

    First table is: 'pret_sav' with field as:

    id | brand | libel | model | series | quantity

    And my second table is: 'stock_reel_sav' with field as:

    id | brand | libel | model | series | quantity

    Imagining that in my table 'stock_reel_sav' I have in my fields:

    id | brand | libel | model | series | quantity
    1 | SAMSUNG | MOBILE | SGHC140 | 12ZES21 | 4

    Since I returned to my table 'pret_sav' the same model (SGHC140)

    I want in my table 'stock_reel_sav' displays 3 quantity.

    Frankly I express myself well I'm not a great professional in sql but I took a lot of tutorial to learn but I'm far from there. Initially I was left with a COUNT but I do not know how to escape and then I went with SUM, I try to do a join like:

    SELECT DISTINCT model, SUM (quantity), SUM (quantity) FROM pret_sav INNER JOIN stock_reel_sav etc...
    But alas, like I always got stuck I do not even know if it was the right solution.

  4. #4
    Join Date
    Nov 2008
    Posts
    1,185

    Re: Subtraction between two SQL tables

    Some modeling problems in your database!
    First table is: 'pret_sav' with field as:

    id | brand | libel | model | series | quantity

    And my second table is: 'stock_reel_sav' with field as:

    id | brand | libel | model | series | quantity

    Imagining that in my table 'stock_reel_sav' I have in my fields:

    id | brand | libel | model | series | quantity
    1 | SAMSUNG | MOBILE | SGHC140 | 12ZES21 | 4
    If "series" is the serial number of a device, how can you have a quantity of 4 with the same serial number? Normally the serial numbers are unique for a device model! Then you have the same columns in your two tables for the same devices. Then you have redundancy of data. I doubt from the name of your table that you registered in the table 'pret_sav' material contained in table 'stock_reel_sav'. That equipment can be lent or not. Why not simply have added a boolean column to the table 'stock_reel_sav' Whether the material is taken (or in this stock which is the same but with a reversed).

    If it is not too late, I advise you to review your data model.

    Returning to your needs ...
    Since I returned to my table 'pret_sav' the same model (SGHC140)

    I want in my table 'stock_reel_sav' displays 3 quantity.
    In other words, you want to update the quantity for each model according to what is # lend?

Similar Threads

  1. automatic subtraction in excel
    By smartsoul2 in forum Windows Software
    Replies: 3
    Last Post: 10-02-2011, 05:58 PM
  2. VPN and routing tables
    By Allison in forum Networking & Security
    Replies: 4
    Last Post: 25-11-2010, 01:02 AM
  3. Problem in random number subtraction
    By Linoo in forum Software Development
    Replies: 4
    Last Post: 05-03-2010, 07:37 PM
  4. How to use Tables in Java?
    By Rob Dizzle in forum Software Development
    Replies: 4
    Last Post: 11-02-2010, 07:04 AM
  5. Problem of subtraction in C
    By Camryn in forum Software Development
    Replies: 5
    Last Post: 30-12-2009, 07:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,991,836.73017 seconds with 17 queries