[TriLUG] MySQL INSERT syntax problem

Michael Rulison 13miketele at bellsouth.net
Tue Dec 5 15:16:37 EST 2006



Robert Dale wrote:
> Are you trying to insert from the select query?  
Yes.
> I don't believe you  can use VALUES with a SELECT...
> Also, you probably want to keep your select columns matched (in order
> and number) with your insert columns
>
> FIRST QUERY:
> INSERT IGNORE p_coin_invoices( invc_cl_id, invc_ts, invc_ts_due )
> SELECT cl_id, next_billing_date, date_add(next_billing_date, INTERVAL
> 21 DAY) FROM cust_extract.name = p_coin_clients.cl_user_name AND
> next_billing_date < '2006-12-01'
>
OK. New SECOND query is below. Taking out VALUES helped but:
    --12/5/2006 3:09:55 PM It says it worked but it does not add rows to
the table
Nevertheless it says:
--Your SQL-query has been executed successfully -- (Query took 0.0388 sec)
This is a new table [p_coin_invoices_2] I created just to make sure
everything was clean. but it seems to make no difference
The select part works, but with the Insert part added it does not.

INSERT IGNORE p_coin_invoices_2( invc_cl_id, invc_ts, invc_ts_due ) -- 3
cols
SELECT cl_id, next_billing_date, DATE_ADD( next_billing_date, INTERVAL 21
DAY ) -- 3 vars
FROM p_coin_clients, cust_extract
WHERE cust_extract.name = p_coin_clients.cl_user_name
AND next_billing_date < '2006-12-01'

-----------------------------------------------------------------------------
Michael Rulison      |     919/782-9576
3256 Lewis Farm Road   Raleigh  NC  27607-6723
eltzruhe at gmail.com
-----------------------------------------------------------------------------



More information about the TriLUG mailing list