-1

Well, I Have four tables and I need to unite those first two and then do a inner join with another union with those other two tables, i'm stuck, thanks anyway

SELECT miRNA, Gene_Symbol FROM 
(SELECT cons.miRNA, cons.Gene_Symbol 
FROM conserved_site_context_scores cons
WHERE cons.miRNA = 'hsa-miR-29c'
UNION 
SELECT noncons.miRNA , noncons.Gene_Symbol 
FROM nonconserved_site_context_scores noncons
WHERE noncons.miRNA = 'hsa-miR-29c'
) AS targetScan

SELECT mirna_name, gene_symbol FROM (
SELECT sc.mirna_name, sc.gene_symbol
FROM hg19_predictions_s_c_aug2010 sc
WHERE sc.mirna_name = 'hsa-miR-29c'
UNION
SELECT oc.mirna_name, oc.gene_symbol
FROM hg19_predictions_0_c_aug2010 oc
WHERE oc.mirna_name ='hsa-miR-29c'
) AS microRNA

INNER JOIN microRNA
ON targetScan.miRNA = microRNA.mirna_name
WHERE targetScan.miRNA = 'hsa-miR-29c';
4

2 回答 2

1

I'm guessing you're trying to figure out how to JOIN the two UNION statements above? If so, give this a try:

SELECT miRNA, Gene_Symbol 
FROM 
   (
   SELECT cons.miRNA, cons.Gene_Symbol 
   FROM conserved_site_context_scores cons
   WHERE cons.miRNA = 'hsa-miR-29c'
   UNION 
   SELECT noncons.miRNA , noncons.Gene_Symbol 
   FROM nonconserved_site_context_scores noncons
   WHERE noncons.miRNA = 'hsa-miR-29c'
) AS targetScan INNER JOIN
   (
   SELECT mirna_name, gene_symbol 
   FROM (
      SELECT sc.mirna_name, sc.gene_symbol
      FROM hg19_predictions_s_c_aug2010 sc
      WHERE sc.mirna_name = 'hsa-miR-29c'
      UNION
      SELECT oc.mirna_name, oc.gene_symbol
      FROM hg19_predictions_0_c_aug2010 oc
      WHERE oc.mirna_name ='hsa-miR-29c'
   ) AS microRNA
      ON targetScan.miRNA = microRNA.mirna_name
WHERE targetScan.miRNA = 'hsa-miR-29c';

I don't think you need the final WHERE criteria at the bottom since it's already included in the UNION.

于 2013-03-22T04:19:46.153 回答
1

Try this:

SELECT miRNA, Gene_Symbol
FROM (
       SELECT cons.miRNA, cons.Gene_Symbol
       FROM conserved_site_context_scores cons
       WHERE cons.miRNA = 'hsa-miR-29c'

       UNION

       SELECT noncons.miRNA, noncons.Gene_Symbol
       FROM nonconserved_site_context_scores noncons
       WHERE noncons.miRNA = 'hsa-miR-29c'
    ) AS targetScan
Inner Join
(
   SELECT mirna_name, gene_symbol
   FROM (
    SELECT sc.mirna_name, sc.gene_symbol
    FROM hg19_predictions_s_c_aug2010 sc
    WHERE sc.mirna_name = 'hsa-miR-29c'

    UNION

    SELECT oc.mirna_name, oc.gene_symbol
    FROM hg19_predictions_0_c_aug2010 oc
    WHERE oc.mirna_name = 'hsa-miR-29c'
    )tbl 
)AS microRNA
    ON targetScan.miRNA = microRNA.mirna_name
WHERE targetScan.miRNA = 'hsa-miR-29c';
于 2013-03-22T04:23:35.627 回答