Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Am I Missing something?

36 views
Skip to first unread message

Tim Ellis

unread,
Jul 3, 2012, 8:23:37 AM7/3/12
to
I have three tables, Table_A, Table_B and Table_C
All rows on Table_A have a corresponding row on Table_B and vice versa
All row on Table_C have a corresponding row on Table_A (and table_B)
Not all rows on Table_A (and Table_B) have corresponding rows on Table_C

Table_A includes a TYPE field - their are two types - "W" and "X"
Table_B includes a COUNT field that holds a numeric value from 0 up
All tables are BTREE Unique on the ID field

I want to select values where either
1) TYPE = W and COUNT > 5
2) TYPE = X and COUNT > 0
3) A record exists on Table_C

SELECT * FROM TABLE_A,TABLE_B
WHERE A.ID = B.ID AND
( (A.TYPE = "W" AND B.COUNT > 5) OR
(A.TYPE = "X" AND B.COUNT > 0) OR
EXISTS (SELECT 1 FROM TABLE_C WHERE C.ID = B.ID)
)

fails with E_US1196 SELECT returned multiple values
The query executes if I omit either the EXISTS line, or the two A.TYPE= lines

I can rewrite the query to explicitly use asn outer join

SELECT * FROM TABLE_A, TABLE_B FULL JOIN TABLE_C on B.ID = C.ID
WHERE A.ID = B.ID AND
( (A.TYPE = "W" AND B.COUNT > 5) OR
(A.TYPE = "X" AND B.COUNT > 0) OR
C.ID IS NOT NULL
)

Which works. But shouldn't the two statements be functionally equivalent?

Ian Kirkham

unread,
Jul 3, 2012, 9:01:33 AM7/3/12
to Ingres and related product discussion forum
Hi Tim,
What you are describing sounds like a bug & I'd suggest logging a call
for this.
Your workaround, given the dataset described, should give the same
results but would be better written with LEFT join instead of FULL join
as the latter has overheads that you don't need and would cause wrong
results if there did happened to be rows in C that were not present in
either A or B.
Regards,
Ian
_______________________________________________
Info-Ingres mailing list
Info-...@kettleriverconsulting.com
http://ext-cando.kettleriverconsulting.com/mailman/listinfo/info-ingres


Tim Ellis

unread,
Jul 3, 2012, 11:25:53 AM7/3/12
to comp.datab...@googlegroups.com, Ingres and related product discussion forum
Thanks Ian
I'll raise a call tomorrow

0 new messages