If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Insert comparison

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-30-08, 14:03
jimbox jimbox is offline
Registered User
 
Join Date: Sep 2008
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 09-30-08, 15:39
BargainPredator BargainPredator is offline
Registered User
 
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;
Reply With Quote
  #3 (permalink)  
Old 09-30-08, 18:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
WHERE datecol >= CURRENT_DATE - INTERVAL 1 DAY
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 09-30-08, 20:48
BargainPredator BargainPredator is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 10-01-08, 09:42
jimbox jimbox is offline
Registered User
 
Join Date: Sep 2008
Posts: 2
Wow thanks guys that is exactly what I was looking for!!!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On