Re: Using case or if to return multiple rows

From: Ragnar <gnari(at)hive(dot)is>
To: Ashish Karalkar <ashish(dot)karalkar(at)info-spectrum(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Using case or if to return multiple rows
Date: 2007-07-12 09:52:08
Message-ID: 1184233928.5778.117.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On fim, 2007-07-12 at 12:15 +0530, Ashish Karalkar wrote:
> I want to select data from two diffrent table based on third tables
> column
> somthing like:
>
>
> select case when t3.date='xxxx' then
> select * from table1
> else
> select * from table 2
> from table3 t3 where t3.date='xxxxx'
>
> Problem is that I have to do it in Plain SQL.

you problem is not quite clear.
do you want to output all rows from table1 (or table2)
for each row of table3?
or does table2 only have one row with date='xxxxx' ?
is 'xxxx' the same date as 'xxxxx' in your example?
if so, how can table2's columns be selected.

are you looking for something like:

select * from table1
where (select date from table3)='xxxx'
UNION ALL
select * from table2
where (select date from table3)<>'xxxx'

this might work if table1 and table2 have compatible schemas, and table3
only has 1 row, and table3.date is NOT NULL

if this is not what you are looking for, you need to be more clear.

gnari

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Pavel Stehule 2007-07-12 11:25:55 Re: Using case or if to return multiple rows
Previous Message Pavel Stehule 2007-07-12 07:09:04 Re: Using case or if to return multiple rows