I have the following query :
SELECT ws_id, n50, num_singletons, num_segments_less_100, kmer, num_all_reads, number_bases_in_contigs,
num_bases_in_singletons
FROM stats_assembly WHERE ws_id IN (
SELECT workflow_steps.id
FROM workflow_steps, workflows
WHERE workflow_steps.workflow_id = workflows.id
AND workflows.sample_id = (
SELECT workflows.sample_id FROM workflows WHERE workflows.id = (
SELECT workflow_id FROM workflow_steps WHERE id = 462
)
AND workflow_steps.submodule_id = 2
)
)
And I want to rewrite it without using subqueries. So far I have been able to do only this:
SELECT ws_id, n50, num_singletons, num_segments_less_100, kmer, num_all_reads, number_bases_in_contigs,
num_bases_in_singletons
FROM stats_assembly
INNER JOIN workflow_steps ON ( stats_assembly.ws_id = workflow_steps.id )
INNER JOIN workflows ON ( workflow_steps.workflow_id = workflows.id )
And I have no idea how to finish it.
Furthermore, this query potentially returns multiple rows but I want to get the row which has MAX(ws_id). Any tips will be greatly appreciated.
idthe Primary Key in every table? – ypercube May 23 '12 at 15:33