Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a very large database and I want to select certain records and then set a column value such as:

SELECT name, email 
FROM table 
WHERE zipcode = 12345 
INTO outfile /tmp/file.csv; 

Then I want to set the mail_flag equal to today's date such as

SET mail_flag = 09012013 

I'm just not sure how to string this together.

share|improve this question
    
Not an very good thing to do Select name, email from table where zipcode = 12345 into outfile /tmp/file.csv; needs an Temporary table and most likely it needs un MyISAM disk based Temporary table what will stress the Disks. –  Raymond Nijland Sep 27 '13 at 18:53
    
Raymond thank you but I don't know how to do that. where can I find how to do that? –  Jay cohen Sep 27 '13 at 19:11
    
you should check your tmp_dir setting off MySQL default is under directory /tmp/ under linux see also this dev.mysql.com/doc/refman/5.7/en/temporary-files.html and you need to look for MYI (MyISAM index file) and MYD (MyISAM data file) if they there then or query method is wrong you could also use EXPLAIN to see you MySQL will handle the query –  Raymond Nijland Sep 27 '13 at 19:44
    
is mail_flag BTW an column of the same table? i assume it is but iam not sure. and can you run an EXPLAIN Select name, email from table where zipcode = 12345. and look if the query needs an Using temporary if not you could be safe but some querys could still need an Using temporary execution –  Raymond Nijland Sep 28 '13 at 16:57
    
add comment

1 Answer

Are you sure you don't just want:

Update mytable set mail_flag=CURDATE() where zipcode=12345

?

Or otherwise I do not understand the question.

share|improve this answer
    
He wants to export this data into an .csv file –  Raymond Nijland Sep 28 '13 at 16:54
    
I'm not too sure about that, actually –  Shlomi Noach Sep 28 '13 at 18:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.