0

How can I modify this query to use exists?

SELECT allele.allele as allele,site.allele_id as allele_id, site.genome_site_id as genome_site_id, popl.popl_id as popl_id,popl.frequency as frequency 
FROM kref.allele as allele 
    join kref.genome_site_allele as site using (allele_id) 
    LEFT JOIN kref.genome_site_allele_popl as popl USING (ref_genome_id, allelism_start, allelism_end, chrom_id, allele_id) 
WHERE ref_genome_id= 2 AND allelism_start=25710014 AND allelism_end=25710015 
    AND chrom_id ='22' 
    AND site.allele_id IN (
        SELECT allele_id 
        from kref.allele 
        where allele IN ('-','C' )
    )
1
  • can you eleborate on what is your goal just to check if you get any results or something else? Commented Nov 8, 2012 at 15:14

1 Answer 1

1

For whatever reason you might want that, here's a semantically equivalent query using EXISTS:

SELECT allele.allele as allele,site.allele_id as allele_id,
       site.genome_site_id as genome_site_id, popl.popl_id as popl_id,
       popl.frequency as frequency
  FROM kref.allele as allele
  JOIN kref.genome_site_allele as site using (allele_id)
  LEFT JOIN kref.genome_site_allele_popl as popl
      USING (ref_genome_id, allelism_start, allelism_end, chrom_id, allele_id)
 WHERE ref_genome_id= 2 
   AND allelism_start=25710014
   AND allelism_end=25710015
   AND chrom_id ='22'
   AND EXISTS (
     SELECT TRUE
     FROM kref.allele
     WHERE allele IN ('-','C')
     AND allele_id = site.allele_id
   )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.