I am working in Oracle 11g.
I have been racking my brain all day trying to figure out how to write a particular SQL statement (am a Java/.NET Developer, would not consider myself a SQL expert)
I have written an inline view (with tons of LEFT OUTER JOINS
and CASE
statements) that sets up the following scenario:
ID (non-unique) | Received
----------------------------
1 Y
1 N
2 N
2 N
2 Y
3 N
3 Y
I need to query the inline view:
If each ID has at least 1 row with a 'Y', return 'Y'.
Otherwise return 'N'.
So for the scenario above, I would return a 'Y'.**
I thought an aggregate function would work, and I've been reading through GROUP BY, ANY/ALL, and Count. However, I did not see
Not asking anyone to write my SQL for me ... if anyone could even suggest a function or technique or article I could read / run down. I guess I don't know enough about complex SQL to know what to search for.
If this is not possible to write, I guess I could look into doing it as a PL/SQL Function. I know that I can use a cursor and track things with variables. However, I thought it would be more efficient to write it as pure SQL (seem to recall the Oracle Optimizer can't see into functions/procedures).
Thank you very much in advance,
Philip