pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Charles Hauser <chauser@duke.edu>
To: PSQL_list <pgsql-sql@postgresql.org>
Subject: help w/ constructing a SELECT
Date: 19 Sep 2002 10:41:15 -0400
Message-ID: <1032446475.22067.29.camel@pandorina.biology.duke.edu> (raw)

Greetings,

Having a problem with a query.
I would like to construct a query which will return a list of all
contigs which are comprised of clones whose 'read' = 'x' (read can be
either 'x' or 'y').

Details:

	A contig may be comprised of more than 1 clone, so in TABLE
clone_contig, there may be multiple entries for a given contig as in:

chlamy_est=> select * from clone_contig;
 clone_id | contig_id 
----------+-----------
     9811 |         1
    82214 |         1
   127472 |         1
    82213 |         1
   112644 |         1
     9810 |         1
    81641 |         2



This SELECT returns contigs comprised of clones whose reads are either
'x' or 'y'. Somehow I need an intersect or NOT comparrison???

SELECT contig.assembly,contig.ace,contig.ver
FROM clone JOIN clone_contig USING (clone_id)
            JOIN contig USING (contig_id)
WHERE clone.read = 'x'
;


Tables:

CREATE TABLE clone_contig(    
clone_id INTEGER REFERENCES clone(clone_id) ON DELETE CASCADE,
contig_id INTEGER REFERENCES contig(contig_id) ON DELETE CASCADE,
UNIQUE(clone_id,contig_id)
);


CREATE TABLE clone (
clone_id SERIAL PRIMARY KEY,
project INTEGER REFERENCES library(project) NOT NULL,
....snip....
read CHAR(1) NOT NULL,
....snip....
UNIQUE (project,plate,row,col,read,ver)
);


CREATE TABLE contig (
contig_id SERIAL PRIMARY KEY,
assembly DATE NOT NULL,
ace INTEGER NOT NULL,
ver INTEGER NOT NULL,
length INTEGER NOT NULL,
seq TEXT NOT NULL,
UNIQUE (assembly,ace,ver)
);


CREATE TABLE clone_contig(    
clone_id INTEGER REFERENCES clone(clone_id) ON DELETE CASCADE,
contig_id INTEGER REFERENCES contig(contig_id) ON DELETE CASCADE,
UNIQUE(clone_id,contig_id)
);


regards,

Charles





view thread (3+ messages)  latest in thread

Message-ID: <1032446475.22067.29.camel@pandorina.biology.duke.edu>
Permalink:  ../1032446475.22067.29.camel@pandorina.biology.duke.edu/
Also on:    postgresql.org/message-id/1032446475.22067.29.camel@pandorina.biology.duke.edu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: chauser@duke.edu
  Subject: Re: help w/ constructing a SELECT
  In-Reply-To: <1032446475.22067.29.camel@pandorina.biology.duke.edu>
  References: <1032446475.22067.29.camel@pandorina.biology.duke.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox