Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2008
    Posts
    2

    Unanswered: Insert comparison

    Hey everyone,

    I am semi familiar with mySQL syntax but am no way a pro so I have come here to ask you pros if this scenario is at all possible:

    I have a "master" table that contains all of my data for my company, it contains sales logs per date example:
    1-1-08 customerid whatwasbought price
    1-2-08 customerid whatwasbought price
    1-2-08 customerid whatwasbought price
    1-2-08 customerid whatwasbought price

    etc.
    My Question:
    I would like to know if it was possible to insert into this table (master) from a different table (smallTable) for only certain dates... now since this is going to be a recurring thing I would like to be able to use a variable or something instead of:
    Insert into Master from smalLTable customerid, whatwasbought, price where date > 1-2-08
    i would like to do it like

    Insert into Master from smalLTable customerid, whatwasbought, price where date > currentDate-1
    -- This is months and months worth of data and the system I'm building is going to have to automatically do this Insert so that is why i need a dynamicValue and not a staticValue

    Is this at all possible or is there a different way to do this? Or am I FUBAR

    Thanks for your time

  2. #2
    Join Date
    Sep 2008
    Posts
    8
    Like this :

    Code:
    INSERT INTO Master(customerid, whatwasbought, price) 
    SELECT customerid, whatwasbought, price FROM smalLTable WHERE date > 1-2-08;

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    WHERE datecol >= CURRENT_DATE - INTERVAL 1 DAY
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Sep 2008
    Posts
    8
    Quote Originally Posted by r937
    WHERE datecol >= CURRENT_DATE - INTERVAL 1 DAY
    I mised that. But the insert on select was more the point that I was trying to highlight

  5. #5
    Join Date
    Sep 2008
    Posts
    2
    Wow thanks guys that is exactly what I was looking for!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •