| Need help with SQL query [message #560955] |
Wed, 18 July 2012 00:16  |
urnikhil
Messages: 42 Registered: March 2008
|
Member |
|
|
Hi All,
I need help with the following sql query.
I have a table named 'x'. It has values as shown below.
COL1 COL2 COL3 COL4 COL5
---- ---- ---- ---- ----
A 1 K 1 N
A 1 K 50 J
A 1 K 99 R
B 2 J 1 N
B 2 J 5 N
C 3 M 8 N
C 3 M 99 U
D 7 R 2 L
I am trying to write a query so that if the value in col4 is "99" for any given set of col1,col2,col3 values, we have to display only that record ignoring the rest in that set. For example, when we select the values from above table, I need the result of the query to look like the following:
COL1 COL2 COL3 COL4 COL5
---- ---- ---- ---- ----
A 1 K 99 R (eliminated two other records)
B 2 J 1 N
B 2 J 5 N
C 3 M 99 U (eliminated one other record)
D 7 R 2 L
Please help me with the query. Thanks a lot.
- Nik.
|
|
|
|
|
|
| Re: Need help with SQL query [message #560963 is a reply to message #560955] |
Wed, 18 July 2012 00:49  |
 |
Michel Cadot
Messages: 54712 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
From your previous SQL topic:
Michel Cadot wrote on Sun, 01 March 2009 21:09...
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter), use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version (4 decimals).
Post a Test case: create table and insert statements along with the result you want with these data...
Hint for one solution: use WHERE NOT EXISTS, if you post a test case, I show you how to do it.
Regards
Michel
|
|
|
|