Re: select with multiple occurences in same table - Mailing list pgsql-sql

From Josh Berkus
Subject Re: select with multiple occurences in same table
Date
Msg-id web-77065@davinci.ethosmedia.com
Whole thread Raw
In response to select with multiple occurences in same table  ("William Herring" <wherring@mail.ifas.ufl.edu>)
List pgsql-sql
WIlliam,

>       Table "inventorytrack"
>  Attribute  |   Type    | Modifier
> ------------+-----------+----------
>  tattoo     | text      |
>  past_group | text      |
>  ranch      | text      |
>  ent_date   | timestamp |
>  indate     | date      |
> 

Are you sure that you're using the most efficient data types for this
table?  And where's your primary key?


> In the above table, I have multiple occurrences of ‘tattoo’.
> However, some
> of the tattoo’s have null value in ‘indate’, some do not.  I would
> like to
> select those tattoos with a null indate, unless there is another
> identical
> tattoo in the table that has  a date value in  ‘indate’.

THis one is easy.  However, I'm not sure exactly waht you want; the
sample return tuples you provided do not match what you asked for!

If you wanted to answer the question above:

SELECT * FROM inventorytrack
WHERE indate IS NULL
AND NOT EXISTS (SELECT tattoo FROM inventorytrack it2WHERE it2.tattoo = inventorytrack.tattoo    AND indate IS NOT NULL
);

-Josh Berkus



______AGLIO DATABASE SOLUTIONS___________________________                                      Josh Berkus Complete
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco
 


pgsql-sql by date:

Previous
From: "William Herring"
Date:
Subject: select with multiple occurences in same table
Next
From: "Robby Slaughter"
Date:
Subject: pl/pgSQL and escaping LIKE clauses