Unix Technical Forum

SQL help needed....

This is a discussion on SQL help needed.... within the Ingres forums, part of the Database Server Software category; --> Hello all, Tbl A contains the following distinct rows: A|A1|A2|O A|A1|A2|S B|B1|B2|O C|C1|C2|S D|D1|D2|O E|E1|E2|S E|E1|E2|O The two A ...


Go Back   Unix Technical Forum > Database Server Software > Ingres

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 10:58 PM
Manny
 
Posts: n/a
Default SQL help needed....

Hello all,

Tbl A contains the following distinct rows:

A|A1|A2|O
A|A1|A2|S
B|B1|B2|O
C|C1|C2|S
D|D1|D2|O
E|E1|E2|S
E|E1|E2|O

The two A rows are identical apart from the col4 values.
The two E rows are identical apart from the col4 values.

Is it possible to select all distinct rows from the table - with the
added twist that if a row is identical to another apart from the col4
value then only select the row with col4 set to 'O'.

In other words rows B, C, D are selected and for A and E rows only the
rows with the col4 value set to 'O' will be selected.

Ta,

Manny

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-20-2008, 10:58 PM
Karl & Betty Schendel
 
Posts: n/a
Default Re: [Info-Ingres] SQL help needed....

At 6:58 AM -0700 7/25/07, Manny wrote:
>Hello all,
>
>Tbl A contains the following distinct rows:
>
>A|A1|A2|O
>A|A1|A2|S
>B|B1|B2|O
>C|C1|C2|S
>D|D1|D2|O
>E|E1|E2|S
>E|E1|E2|O
>
>The two A rows are identical apart from the col4 values.
>The two E rows are identical apart from the col4 values.
>
>Is it possible to select all distinct rows from the table - with the
>added twist that if a row is identical to another apart from the col4
>value then only select the row with col4 set to 'O'.



select col1, col2, col3, min(col4)
from table
group by col1, col2, col3

will do it.

Or, if you have values in col4 smaller than O for the
doubled-up rows, try this:
select col1, col2, col3,
case when count(*)>1 then 'O' else min(col4) end
from table
group by col1, col2, col3

in this version max would work as well as min, all you want
is a way to get the (one) value for col4 when the other
columns are not duplicated elsewhere.

Karl
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-20-2008, 10:58 PM
Manny
 
Posts: n/a
Default Re: SQL help needed....

Karl,

Thats works a treat.

Thanks,

Manny

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:39 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com