initial trials for subquery to return more than one crime for a trial
Posted by sarneil on 31 Aug 2010 in Activity Log
There are about a dozen trials in which 2 crimes are being tried. (i.e. the crimes table has about 12 more records than then trials table). I've eventually got to figure out how to return results which include more than one crime where appropriate.
This simple snippet returns a row for each record in the crimes table which has the same trial_id_fk as at least one other record in the crimes table. A more sophisticated version of this kind of will have to find its way as a subquery into the real query. Similarly for any other data with a similar relationship to the trial table.
SELECT crime_text,trial_id_fk FROM crimes AS temp
WHERE 1 < (SELECT COUNT(*) FROM crimes WHERE crimes.trial_id_fk = temp.trial_id_fk);