Results 1 to 3 of 3
Hi,
I am trying to output one field of a mysql database to a file but with a condition of another fields data.
i.e...
field_a
field_b
field_c
1
a
Hello
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-04-2012 #1Just Joined!
- Join Date
- Feb 2012
- Posts
- 2
Mysql SELECT INTO OUTFILE help
Hi,
I am trying to output one field of a mysql database to a file but with a condition of another fields data.
i.e...
field_a field_b field_c 1 a Hello 1 b World 2 c Please 2 d Help
in the above table I want to output field_c which I know I do with the following:
BUT... could my output file contain just field_c data but only if field_a = 1Code:SELECT field_c INTO OUTFILE '/tmp/file.txt' FROM table;
so in this instance my output would be hello world.
Thanks in advance for any help
- 02-05-2012 #2Just Joined!
- Join Date
- May 2011
- Location
- NJ
- Posts
- 56
Code:SELECT field_c INTO OUTFILE '/tmp/file.txt' FROM table WHERE field_a=1;
- 02-05-2012 #3Just Joined!
- Join Date
- Feb 2012
- Posts
- 2
Just an update on this in case anyone else is looking for an answer.
The code required to do this is
It has made the output file a little messy but easily fixed with this:Code:SELECT GROUP_CONCAT(field_c SEPARATOR ' ') AS output INTO OUTFILE '/tmp/file.txt' FROM table WHERE field_a = 1
Thanks to those who looked anywayCode:tr ' ' '\n' < file.txt > output.file.txt



