Re: SELECT Query

From: Jean-Luc Lachance <jllachan(at)nsd(dot)ca>
To: Scott Taylor <scott(dot)taylor(at)4i-dotcom(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT Query
Date: 2002-11-01 16:04:55
Message-ID: 3DC2A627.9E5B88FE@nsd.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

select * from acc_trans where chart_id = 10074
union
select * from acc_trans where tx_transaction = 10088
and exists ( select * from acc_trans where tx_transaction = 10088 and
chart_id = 10074);

Scott Taylor wrote:
>
> Below is the result of a query on my table. I want to only return those
> transactions that have a chart_id=10074, and if trans_id 10088 is one of
> those, I want to return all 3 rows with that trans_id.
>
> accs=# select * from acc_trans;
> trans_id | chart_id | amount | transdate | source | cleared |
> fx_transaction
> ----------+----------+----------+------------+--------------+---------+----------------
> 10088 | 10004 | -2062.12 | 2002-03-01 | | f | f
> 10088 | 10037 | 1755 | 2002-03-01 | | f | f
> 10088 | 10074 | 307.12 | 2002-03-01 | | f | f
> 10092 | 10004 | -528.75 | 2002-03-12 | | f | f
> 10092 | 10037 | 450 | 2002-03-12 | | f | f
> 10092 | 10074 | 78.75 | 2002-03-12 | | f | f
> 10088 | 10004 | 2062.12 | 2002-03-07 | | f | f
> 10088 | 10002 | -2062.12 | 2002-03-07 | | f | f
> 10096 | 10016 | 1169.75 | 2002-03-12 | | f | f
> 10096 | 10047 | -1169.75 | 2002-03-12 | | f | f
> 10096 | 10002 | 1169.75 | 2002-03-11 | | f | f
> 10096 | 10016 | -1169.75 | 2002-03-11 | | f | f
> 10098 | 10016 | 283.91 | 2002-03-12 | | f | f
> 10098 | 10044 | -283.91 | 2002-03-12 | | f | f
> 10099 | 10016 | 137.6 | 2002-03-12 | | f | f
> 10099 | 10045 | -137.6 | 2002-03-12 | | f | f
> 10100 | 10016 | 163.74 | 2002-03-12 | | f | f
> 10100 | 10046 | -163.74 | 2002-03-12 | | f | f
> 10092 | 10004 | 528.75 | 2002-03-20 | | f | f
> 10092 | 10002 | -528.75 | 2002-03-20 | | f | f
> 10101 | 10004 | -528.75 | 2002-03-20 | | f | f
> 10101 | 10037 | 450 | 2002-03-20 | | f | f
> 10101 | 10074 | 78.75 | 2002-03-20 | | f | f
>
> Regards
>
> Scott
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-11-01 16:09:59 Re: postgres on a FreeBSD 4.5 box
Previous Message Bruno Wolff III 2002-11-01 15:22:43 Contribute link broken