mysql - Export table to csv to multiple files based on column from different table -
i need dump table multiple files based on column value in table.
i want use mysql commmand line, not through scripting language. possible?
e.g.:
table has
(id, name, stuff)
, name
unique
table b has
(id, name, start, end)
i want dump rows in b name
exists in a
, each own file based on name
.
in sql, this:
select * b name = 'brad' (exists in a) outfile '/home/csv/brad.csv' fields terminated ',' optionally enclosed '"' lines terminated '\n'
except each , every name exists in a.
to make sure name
exists in table a
join a
, b
on name:
select * b inner join on b.name = a.name name = 'brad'
as varying outfile
name, don't think there's way without programming/scripting. can mysql procedure using execute
; there's bare-bones example here can adapt. general approach create cursor of distinct names, scan , build/execute sql (including outfile
value) each name.
Comments
Post a Comment