Very useful SQL commands

Description of what the SQL command does

SLQ CODE HERE

Description of what the SQL command does

SLQ CODE HERE

# Find TaxonomyStat records with non-existent contigs:

select * from taxonomy_stats ts left join contigs c on ts.contig_id = c.id where c.id is null;

#Delete TaxonomyStat records with non-existent contigs:

delete ts from taxonomy_stats ts left join contigs c on ts.contig_id = c.id where c.id is null;

# find features where the contig_id field is present, but refers to a non-existing contig

select f.id, f.name from features f where not exists (select * from contigs c where f.contig_id = c.id);

# get sequences for building blast db from ggkbase_production (used for building blast databases)

select c.id, c.name, c.gcode, s.value from contigs c join sequences s on s.contig_id = c.id into outfile '/tmp/ggkbase_contigs_05012017.tsv' fields terminated by '\t' enclosed by '' lines terminated by '\n';

# get features for building blast db from ggkbase_production (used for building blast databases)

select f.id, f.name, f.contig_id, f.category, f.from, f.to, f.complement from features f into outfile '/tmp/ggkbase_features_11082017.tsv' fields terminated by '\t' enclosed by '' lines terminated by '\n';