I have 10 machines and I have created one table for each machine I am collecting data from, each machine has the exact same columns in their tables. Columns are: order#, timestamp, pv, mv, sp. The operator will select order# prior to running the machines so I want the MySQL database to export rows specific to that order number to a new CSV file named "order#.csv" every time a new order# is entered. I am very new to databases so this is what I have this far:
(SELECT 'Order Number','Timestamp','Mv','Pv','Sp')
union
(select orderNo,Timestamp,Mv,Pv,Sp
from pid
where orderNo = new.orderNo
INTO OUTFILE 'H:/test.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n');
In the end what I am trying to achieve is having one CSV file with all machine data collected when the machine is working on ONE order, however long it's been working on that order. So that I will have one CSV file for one order on one machine, and I can go back and look at the machine performance for different orders. Any help on this is greatly appreciated!