Assume that you have execute file above and put data into mySQL DB.
You can use the select command to write to csv file.
SELECT email, name FROM people INTO OUTFILE 'yourfile.csv' FIELDS
TERMINATED BY ','
In you updated comment, you simply want to do mapping from people name from text file to SQL command to perform query. If you break down the question, it will become two tasks. First is to select name from the given list, which can be done by:
SELECT email, name FROM people WHERE name IN ('john', 'alice', 'bob') INTO
OUTFILE 'yourfile.csv' FIELDS TERMINATED BY ','
Above will produce a mapping according to the given list. But your second need is to get that list from text file. One way to do so is to transform a "one-name-per-line" to a "list-of-name-with-comma" using sed
and tr
utilities.
cat your-name-list.txt | sed -e "s/\([a-zA-Z0-9\=\.\-]*\)/'\1'/g" | tr "\n" ","
I don't know what is your environment. but basically, you want to use the result from this as a query condition in SQL above. Hope this give you enough idea.