Home » SQL & PL/SQL » SQL & PL/SQL » SQL Query to be grouped based on Column values
SQL Query to be grouped based on Column values [message #672515] Wed, 17 October 2018 03:58 Go to next message
sober_sandy
Messages: 1
Registered: September 2008
Junior Member
Hello,

How can I query a table to fetch records for each process_id. If there is 'Match' & 'No Match' then output should have
'Match'. If all are 'No Match' output should be 'No Match'

create table t1 (p_id number, result varchar2(100));

Insert into T1 (p_id,result) values ('74','Match');
Insert into T1 (p_id,result) values ('107','No Match');
Insert into T1 (p_id,result) values ('107','No Match');
Insert into T1 (p_id,result) values ('107','Match');
Insert into T1 (p_id,result) values ('110','No Match');
Insert into T1 (p_id,result) values ('110','No Match');
Insert into T1 (p_id,result) values ('110','No Match');
Insert into T1 (p_id,result) values ('115','Match');
Insert into T1 (p_id,result) values ('115','Match');

Output
=======

74 Match
107 Match
110 No Match
115 Match

Thanks !!
Sandy
Re: SQL Query to be grouped based on Column values [message #672516 is a reply to message #672515] Wed, 17 October 2018 04:39 Go to previous message
Michel Cadot
Messages: 67374
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Welcome to the forum.
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Indent the code, use code tags and align the columns in result.
If you don't know how to format the code, learn it using SQL Formatter.
Use the "Preview Message" or "Preview Quick Reply" button to verify.

Also always post your Oracle version, with 4 decimals, as most often solution depends on it.

SQL> select p_id, min(result) result from t1 group by p_id order by p_id;
      P_ID RESULT
---------- -----------------------------------------------------------------------------
        74 Match
       107 Match
       110 No Match
       115 Match

Previous Topic: Count of Pending, Failed, Running, Completed records
Next Topic: Written Assignment-Printing a Record Using an If Statement
Goto Forum:
  


Current Time: Tue Sep 29 22:37:03 CDT 2020