Question

I have three different table as mention below

mRNA_GO

  • MSU7_LOC
  • GO_ID

Gene Ontology

  • GO_ID (Primary Key)
  • Category
  • Term
  • Evidence

miRNA_mRNA

  • miRNA_ID
  • MSU7_LOC

Table 1 is connected with table 2 by GO_ID and with table 3 by MSU7_LOC.

I want following columns in my output.

  • table1.MSU7_LOC
  • table2.GO_ID
  • table2.Category
  • table2.term
  • table2.Evidence
  • tabke3.miRNA_ID

I have written two diff query

Query 1

select gene_ontology.go_id , gene_ontology.category, gene_ontology.evidence, gene_ontology.term , mrna_go.MSU7_LOC 
       from gene_ontology  inner join mrna_go on mrna_go.go_id = gene_ontology.go_id 
       where mrna_go.go_id in ('GO:0009058') ;

Which will give me following columns

  • table1.MSU7_LOC
  • table2.GO_ID
  • table2.Category
  • table2.term
  • table2.Evidenc

Query 2

SELECT mrna_go.go_id, mirna_mrna.mirna 
       from  mirna_mrna inner join  mrna_go on mrna_go.MSU7_LOC = mirna_mrna.MSU7_LOC 
       where mrna_go.go_id in ('GO:0009058') ;

which will give me

  • table2.GO_ID
  • tabke3.miRNA_ID

Can any one tell me how can I get the output using only one query not two different query..

Was it helpful?

Solution

Just join third table

SELECT 
mg.go_id,
mm.mirna ,
g.go_id , 
g.category, 
g.evidence, 
g.term , 
mg.MSU7_LOC 
FROM  mirna_mrna mm
inner join  mrna_go mg on mg.MSU7_LOC = mm.MSU7_LOC 
inner join  gene_ontology g  on mg.go_id = g.go_id 
where mg.go_id in ('GO:0009058') ;

OTHER TIPS

just add a 2nd join in like;

SELECT gene_ontology.go_id , gene_ontology.category, gene_ontology.evidence, gene_ontology.term , mrna_go.MSU7_LOC, mrna_go.go_id, mirna_mrna.mirna 
  FROM gene_ontology  
  INNER JOIN mrna_go ON mrna_go.go_id = gene_ontology.go_id 
  INNER JOIN mirna_mrna ON mrna_go.MSU7_LOC = mirna_mrna.MSU7_LOC
  WHERE mrna_go.go_id IN ('GO:0009058') ;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top