Results output in a single line in a Table

Afternoon people,
I have a scenario by hand, and I was hoping to get some advice. I could write a PL/SQL program and everything would be fine. I was hoping if there was a way to do it in SQL and not necessary to create a new subprogramme for this. I already have a PL/SQL program that populates a table. I now want to use these data and output in some way.

Any help is greatly appreciated and is not something I have to solve this evening. :)

Script to create table and insert records into him:
drop table FLIGHT_ROUTES;

  CREATE TABLE FLIGHT_ROUTES
   (FLIGHT_NO           VARCHAR2(7),
    ROUTE_ID            NUMBER,
    DAY_OF_OPERATION    NUMBER,
    ORIGIN              VARCHAR2(3),
    DESTINATION         VARCHAR2(3),
    STOPVER             VARCHAR2(3),
    ROUTE_TYPE          VARCHAR2(1)
   )
/


REM INSERTING into FLIGHT_ROUTES
Insert into FLIGHT_ROUTES (FLIGHT_NO,ROUTE_ID,DAY_OF_OPERATION,ORIGIN,DESTINATION,STOPVER,ROUTE_TYPE) values ('UX-1001',1,1,'SFO','LAX',null,'D');
Insert into FLIGHT_ROUTES (FLIGHT_NO,ROUTE_ID,DAY_OF_OPERATION,ORIGIN,DESTINATION,STOPVER,ROUTE_TYPE) values ('UX-1001',1,2,'SFO','LAX',null,'R');  -- Record 2
Insert into FLIGHT_ROUTES (FLIGHT_NO,ROUTE_ID,DAY_OF_OPERATION,ORIGIN,DESTINATION,STOPVER,ROUTE_TYPE) values ('UX-2001',2,1,'SFO','JFK',null,'D');
Insert into FLIGHT_ROUTES (FLIGHT_NO,ROUTE_ID,DAY_OF_OPERATION,ORIGIN,DESTINATION,STOPVER,ROUTE_TYPE) values ('UX-2001',2,2,'SFO','JFK','ORD','D');
Insert into FLIGHT_ROUTES (FLIGHT_NO,ROUTE_ID,DAY_OF_OPERATION,ORIGIN,DESTINATION,STOPVER,ROUTE_TYPE) values ('UX-2001',2,3,'SFO','JFK','DEN','R');  -- Record 5
Insert into FLIGHT_ROUTES (FLIGHT_NO,ROUTE_ID,DAY_OF_OPERATION,ORIGIN,DESTINATION,STOPVER,ROUTE_TYPE) values ('UX-3001',3,1,'LAX','JFK','YYZ','D');
Insert into FLIGHT_ROUTES (FLIGHT_NO,ROUTE_ID,DAY_OF_OPERATION,ORIGIN,DESTINATION,STOPVER,ROUTE_TYPE) values ('UX-3001',3,2,'LAX','JFK','YYC','D');
Insert into FLIGHT_ROUTES (FLIGHT_NO,ROUTE_ID,DAY_OF_OPERATION,ORIGIN,DESTINATION,STOPVER,ROUTE_TYPE) values ('UX-3001',3,3,'LAX','JFK','YUL','D');
What I want to do, it's the results by flight number, origine1, Target1, Origin2, Destination 2 and 3 of origin, 3 output Destination. Combinations of numbers maximum per flight is 3. The other condition is that the list should show only the origin and destination and stopover if the time of day it's flight. If it's a red eye, then don't show this option. Record 2 would be completely omitted here because it's a Red Eye flight, and Record 5 may be omitted for origin/Destination/stopover flight UX-2001 3.
Flight_No       Origin1     Destination1    Stopover 1      Origin2          Destination2      Stopver2      Origin3    Destination3     Stopover3
============================================================================================================================================================
UX-1001         SFO         LAX
UX-2001         SFO         JFK                             SFO              JFK               ORD
UX-3001         LAX         JFK             YYZ             LAX              JFK               YYC           LAX        JFK              YUL
Published by: Roxyrollers on Sep 9, 2011 15:59

Published by: Roxyrollers on Sep 9, 2011 15:59

Published by: Roxyrollers on Sep 9, 2011 16:00

Hello

Assuming that day_of_operation is what determines whether a line is 1, 2 or 3:

WITH     got_r_num     AS
(
     SELECT     f.*
     ,     ROW_NUMBER () OVER ( PARTITION BY  flight_no
                               ORDER BY          day_of_operation
                       ) AS r_num
     FROM    flight_routes        f
     WHERE     route_type     != 'R'
)
SELECT       flight_no                              || ',' ||
       MAX (CASE WHEN r_num = 1 THEN origin      END)     || ',' ||     -- Origin 1
       MAX (CASE WHEN r_num = 1 THEN destination END)     || ',' ||     -- Destination 1
       MAX (CASE WHEN r_num = 1 THEN stopver     END)     || ',' ||     -- Stopover 1
       MAX (CASE WHEN r_num = 2 THEN origin      END)     || ',' ||     -- Origin 2
       MAX (CASE WHEN r_num = 2 THEN destination END)     || ',' ||     -- Destination 2
       MAX (CASE WHEN r_num = 2 THEN stopver     END)     || ',' ||     -- Stopover 2
       MAX (CASE WHEN r_num = 3 THEN origin      END)     || ',' ||     -- Origin 3
       MAX (CASE WHEN r_num = 3 THEN destination END)     || ',' ||     -- Destination 3
       MAX (CASE WHEN r_num = 3 THEN stopver     END)  AS csv_text            -- Stopover 3
FROM       got_r_num
GROUP BY  flight_no
ORDER BY  flight_no
;

Output:

CSV_TEXT
-------------------------------------------
UX-1001,SFO,LAX,,,,,,,
UX-2001,SFO,JFK,,SFO,JFK,ORD,,,
UX-3001,LAX,JFK,YYZ,LAX,JFK,YYC,LAX,JFK,YUL

It's not assume origine1 is always on the same line with day_of_operation = 1. Origine1 will take place from the line with the day_of_operation, besides the red eyes. Similarly, origin2 will take place of the line with the 2nd day_of_operation below, if this value is 2, or not.
If your data is such that the line containing day_of_operation = n will be necessarily nth one low, not to mention the eyes red, then you don't need the subquery got_r_num; Just use your real of the table (with the route_type WHERE condition! = 'R') and use the day_of_operation where I used r_num. (it's what the solution of Solomon, which I saw,.)

Published by: Frank Kulash, Sep 9, 2011 16:47

Published by: Frank Kulash, Sep 9, 2011 16:53

Tags: Database

Similar Questions

  • Merge two lines & show to a single line in the table results

    Hi, I need to merge 2 rows with 3 columns in a single row in a table view

    The passes are currently displayed in form:


    Revenue-Revenue (Prior_Month) project No.-(Current_Month)
    123123 10000
    20000


    Recipes are a single column with recipes for diffreent period.
    10000 is for may
    20000 is for April

    Project NOT because both are the same, just the periods are different. If I'm not display period I need to merge the 2 rows & show as

    Revenue-Revenue (Prior_Month) project No.-(Current_Month)
    123123-10000-20000


    Please let me know how we can achieve this?

    thanx
    Pankaj

    .

  • replace the carriage return, displaying the output on a single line

    [oracle@ccoshs02xvdbs01 ~] $ sqlplus deploy_ctl/deploy_ctl

    SQL * more: Production version 11.2.0.1.0 on Mon Mar 28 10:21:05 2011

    Copyright (c) 1982, 2009, Oracle. All rights reserved.


    Connected to:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
    With partitioning, OLAP, Data Mining and Real Application Testing options


    Modified session.

    10:21:05 SQL > insert into test (b) values ("this is stop
    10:21:38 2 space are now ');

    1 line of creation.

    10:21:47 SQL > commit;

    Validation complete.

    10:21:49 SQL > select test b where b as "this % ';

    B
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    It is stop
    space wear now


    10:22:07 SQL > select replace (b, chr (13)) of the test where b as "this % ';

    REPLACE (B, CHR (13))
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    It is stop
    space wear now


    10:22:56 SQL > select replace (b, chr (13), chr (32)) test fix where b as "this % ';

    DIFFICULTY
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    It is stop
    space wear now


    10:24:19 SQL >


    I would lilke to display on the same line.

    Thank you.

    Hello

    SQL> select translate(b,chr(13)||chr(10),chr(32)) fix from test where b like 'this%';
    
    FIX
    ----------------------------------------------------------------------------------------------------
    this is stopspace now carry on
    
    SQL> select translate(b,chr(13)||chr(10),' ') fix from test where b like 'this%';
    
    FIX
    ----------------------------------------------------------------------------------------------------
    this is stopspace now carry on
    

    -Pavan Kumar N

  • How to change the background color of a single line

    Hi, OTN,.

    I use JDeveloper with ADF faces 11.1.1.2 in the view layer. My question is how to change the background color of a single line in af:table?.

    Hi idir Mitra
    You can use EL to bind column for example inlineStyle (#{row.id == null?' background-color: rgb (255,214,165);':'background-color:red'})})

    Cordially Abhilash.S

  • the formatting generated XML using XMLELEMENT() my output approximates to a single line, I want to be in an XML format

    Hi I have a problem in the formatting of XML file, that I generated with xmlelement() when I run it gives me putput in one line

    is it possible that I got my output as an XML file...

    This is the expected behavior. PRETTY print (ing) is required for humans. XML parsers do not need XML to be pretty printed. If you open the XML file in a browser such as Windows Explorer or Firefox, the browser will display enough output for you.

    In all, the exit 'single line' is made for PERFORMANCE reasons (lack of useless end of line and CTRL line breaks etc.)

    SELECT xmlelement ("employee name", model ") as"RESULT XML.

    FROM DUAL;

    X

    SELECT xmlelement ("employee name", xmlelement ("name", false))

    , xmlelement ("LastName", dummy)

    ) as "RESULT XML.

    FROM DUAL;

    X X

    XMLSERIALIZE enough to print the result if necessary via indentation

    SELECT XMLSERIALIZE (SIZE of withdrawal CONTENT xmlelement ("Employee Name", xmlelement ("name", model), xmlelement ("LastName", false)) as CLOB = 1).

    FROM DUAL;

    X

    X

  • join in the query with the result of a single line

    Hi all

    I have two tables
    create table item(item_id number primary key,
    item_desc varchar2(200));
    
    create table item_properties(item_id number references item(item_id),
    property_name varchar2(20),
    property_value varchar2(100));
    I insert the following records
    insert into items values(1,'CPU');
    insert into item_properties values(1,'RAM','2gb');
    insert into item_properties values(1,'PROCESSOR','2ghz');
    insert into item_properties values(1,'HARDDISK','2ghz');
    commit;
    now I want a query that produces the following results
    item_id      RAM      PROCESSOR         HARDDISK
    1              2gb        2ghz              2TB
    How to generate this result?
    I create a query, but it generates several lines, instead I need a single line like above.
    select i.item_id,p.property_value from items i , item_properties p
    where i.item_id=p.item_id and i.item_id=1;
    Kind thanks.

    Published by: Maahjoor on May 7, 2013 12:22 AM
    select i.item_id,
           max(decode(p.property_name,'RAM',p.property_value)) ram,
           max(decode(p.property_name,'PROCESSOR',p.property_value)) processor,
           max(decode(p.property_name,'HARDDISK',p.property_value)) hd
    from items i , item_properties p
    where i.item_id=p.item_id
    and i.item_id=1
    group by i.item_id;
    

    Or pivot to 11g

    with details as
    (
    select i.item_id,p.property_name,p.property_value
    from item i , item_properties p
    where i.item_id=p.item_id
    and i.item_id=1
    )
    select *
    from details
    pivot
     (
       max(property_value) for property_name in ('RAM','PROCESSOR','HARDISK')
     );
    

    Published by: JAC on May 7, 2013 13:04

  • return results as a query of single line sup.

    Hello

    It's my current query
    WITH car as (SELECT 'FORD' make FROM DUAL UNION SELECT 'TOYOTA' make FROM DUAL UNION SELECT'BMW' make FROM DUAL UNION SELECT 'FIAT' make FROM DUAL)
    SELECT * FROM CAR
    Which is: -.
    BMW
    FIAT
    FORD
    TOYOTA
    However, the actual output required: -.
    'BMW, FIAT, FORD, TOYOTA'
    that is, all turned around on a single line.
    Any ideas on how to do this?

    Thanks in advance!
    David

    Or

    SQL> ed
    Wrote file afiedt.buf
    
      1  WITH car as (SELECT 'FORD' make FROM DUAL UNION
      2               SELECT 'TOYOTA' make FROM DUAL UNION
      3               SELECT'BMW' make FROM DUAL UNION
      4               SELECT 'FIAT' make FROM DUAL)
      5  SELECT ltrim(sys_connect_by_path(make,','),',') as makes
      6  FROM (select make, row_number() over (order by make) rn from CAR)
      7  where connect_by_isleaf = 1
      8  connect by rn = prior rn + 1
      9* start with rn = 1
    SQL> /
    
    MAKES
    ------------------------------------------------------------------------
    BMW,FIAT,FORD,TOYOTA
    
    SQL>
    
  • given in the lines, combine them in a single line

    Hello world

    I have programmed plsql to organize data based on a condition, but I need to do it directly in sql, if possible, once the value of the line in another line to combine in a single line, for example

    Header 1 Header 2 Header 3
    A77A84A12
    A12A10A11
    A30A44A42
    A77A02A70

    A08

    A09A86A08

    The goal

    Header 1 Header 2 Header 3 Header 4 Header 5 Heading 6
    A02A10A11A12A77A84
    A08A09A86
    A30A42

    A44

    If you can see the line no 2 & 4 there is A12, A77 who do declare on line no 1, so I need to combine and so on.

    example of data

    CREATE TABLE testrows (col1 VARCHAR2 (10), col2 VARCHAR2 (10), col3 VARCHAR2 (10));

    INSERT INTO testrows

    VALUES ('77', 'A84', 'A12');

    INSERT INTO testrows

    VALUES ("A12", "A10", "A11");

    INSERT INTO testrows

    VALUES ('A30', 'A44', "A42");

    INSERT INTO testrows

    (col1, col2

    )

    VALUES ("A08", "A09"

    );

    INSERT INTO testrows

    (col1, col2

    )

    VALUES ('A86","A08"

    );

    INSERT INTO testrows

    VALUES ('A77","A02","A70");

    Kind regards

    Hello

    I'm not sure that understand what you want.  You must explain in more detail, citing specific examples.

    Why won't you 'The A70' in the results?

    Maybe you want something like this:

    WITH got_r_num AS

    (

    SELECT col1, col2, col3

    ROWNUM AS r_num

    OF testrows

    )

    got_grp AS

    (

    SELECT the val

    MIN (val CONNECT_BY_ROOT) AS grp

    -The following 3 lines are necessary only if rotating into discrete columns

    -, ROW_NUMBER () OVER (PARTITION OF MIN (val CONNECT_BY_ROOT)

    --                               ORDER BY      val

    --                             )          AS c_num

    OF got_r_num

    UNPIVOT (val

    FOR the collar (col1, col2, col3)

    )

    CONNECT BY NOCYCLE (val = val PREREQUISITE AND r_num <> r_num PREREQUISITE)

    OR (val <> val PREREQUISITE AND r_num = PRIOR r_num)

    GROUP BY val

    )

    SELECT LISTAGG (val, ",") THE Group (ORDER BY val) AS val_list

    OF got_grp

    GROUP BY grp

    ORDER BY grp

    ;

    The results I get include "The A70" and are in a tall column concatenated, but are also what you asked:

    VAL_LIST

    ----------------------------------------

    A02, A10, A11, A12, A70, A77, A84

    A08 A09, A86

    A30, A42, A44

    The number of columns in the output must be hard-coded in the application.  If you want the number of columns depends on what the search query, you need dynamic SQL statements.  The following all the addresses this issue:

    Re: 4. How can I convert rows to columns?

    Re: County report and the sum of the number of rows by multiple columns

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:4471013000346257238

  • How can I add a spell checker this spelling laurys for a single line?

    I want a spell checker that checks my spelling for just a single line. For example, Ebay feedback is only one line long then how I spell check my typed in response? Thank you.

    You can do this by changing a hidden preference

    1. Type of topic: config in the address bar and press on enter, accept the message of warning that is displayed and you will be taken to a list of preferences
    2. In the upper search box, type out, will you limit the results to a small number of preferences
    3. Double-click the layout.spellcheckDefault preference and change its value to 2, which will allow the spell on simple lines

    See http://kb.mozillazine.org/Layout.spellcheckDefault for more details about this preference

  • Reading single line of the text file

    I use the following code to read a .txt file

    private String readTextFile (String fName) {}
    String result = null;
    FileConnection fconn = null;
    DataInputStream is = null;
    try {}
    fconn = (FileConnection) Connector.open (fName, Connector.READ);
    is = fconn.openDataInputStream ();
    Byte [] = IOUtilities.streamToBytes (is) data;
    result = new String (data);
    } catch (IOException e) {}
    System.out.println (e.getMessage ());
    } {Finally
    try {}
    If (null! = is)

    is. Close();
    If (null! = fconn)
    fconn. Close();
    } catch (IOException e) {}
    System.out.println (e.getMessage ());
    }
    }
    return the result;
    }

    I want to print a single line instead of the file around so I read that I need to store the contents of the file into an array and then get the index of the line. Problem is that I couldn't find any information on how to do it. Can someone give me a shot. Thanks in advance.

    This isn't a problem with encoding. You just need to do a little extra accounting and adjust start and end indices to remove these characters. To treat the "\r\n" of line termination style, you can maintain a flag (initially false) to indicate that the previous line ended with a \r; If a line begins with \n, it should be treated as the end of a line (empty) if the flag is true (in which case it should be ignored).

    If you want to extract all lines (not just the first), then it may be easier to do this accounting while avoiding a separate function. Something like this (untested):

    // read the file into a byte array 'data'; then:
    Vector lines = new Vector();
    boolean endCR = false;
    int start = 0;
    for (i = start; i < data.length; ++i) {
      if (data[i] = 0xD) {
        lines.addElement(new String(data, start, i - start));
        endCR = true;
        start = i + 1;
      } else if (data[i] = 0xA) {
        if (endCR && i == start) {
          start++;
          endCR = false;
        } else {
          lines.addElement(new String(data, start, i - start));
          start = i + 1;
        }
        endCR = false;
      }
    }
    String[] results = new String[lines.size()];
    lines.copyInto(results);
    
  • Data from multiple rows in single line in BI publisher 11g

    Hello

    I receive documents in multiple lines

    for example

    ID case1, case3 CAS2

    1 C1

    1 C1

    1                 C2

    1                              C4

    Now, I want to make it as a single line, output desired is

    ID Case1, Case3 CAS2

    1 C1 C2 C4

    is it possible, please let me know.

    Thanks in advance

    Kind regards

    Sam

    He seems to do at the level of the model.

    Could you please post your example of xml data?

  • SQLDEV 4.1: Release of report using the dbms_output is all wrapped up in a single line as if new_line is not interpreted

    I develop a report that uses the dbms_output to output messages. However what type of report is set to "PLSQL DBMS Output". the output is all wrapped up in a single line, as if the new lines are not interpreted. If I put it as a "Script", I don't get anything.

    Is there a magic definition that I'm missing? My pl/sql block has dbms_output.enable and several dbms_output.put_line calls and it's on Windows 7 64 bit with Java 1.7.

    Thanks in advance

    the dbms_output is rendered in HTML format in this Panel. So if you want a new line, add a '
    "to your channel.

    HTML support is pretty basic as the HTML3 spec.

    Here is an example

    http://www.thatjeffsmith.com/archive/2012/04/substitution-variables-HTML-reports-in-SQL-Developer/

  • Replace or remove all single line breaks in a Blob

    Hello

    I want to remove/replace all new simple lines (NOT the carriage return / new line) in a BLOB.

    I tried to convert the BLOB in a clob, and then replace all occurrences of new lines of simple with the function replace (for example replace (clob, 10),)
    I even cut the clob into small pieces of varchar2 and tried to apply the function replace etc., but without success!

    I'd be happy if someone could give me a tip how I could fix this problem.

    I use
    Request 4.1.0.00.32 Express on
    Oracle 10g (10.2.0.4.0 - 64 bit)

    Thank you
    Johnny

    Johnny Be Good wrote:
    Hi Paul,.

    the answer to your first question is simple. I use a blob instead of a clob object because I download a file (csv) using an element "Browse file".
    The file is then stored in FLOWS_FILES. WWV_FLOW_FILE_OBJECTS$ (wwv_flow_files) that stores the file in a blob (blob_content) column.

    What to do now is to store the contents of the BLOB to a file in a directory in order to to use as an external file.
    After this, I question the external file and merge the contents into a normal table within the database.

    The problem I have now is that sometimes downloaded csv files have 'broken data sets' in the way that a line (a single dataset), which was divided into
    two or more rows (with a single line break at the end of each line instead of a carriagereturn/linefeed to the normal lines).
    Sometimes, when the lines matching/data sets contain a very large text (e.g. 3000 characters) in a single column and MS excel (the tool used to record the original excel in csv file) can not handle this long texts of a column and breaks the content of a line into multiple lines in a cell.

    However, I need to "Break" the broken data sets in the blob downloaded by removing (or replace) single line breaks, which are an indication of a split data set.

    In view of this process. I converted to CLOB BLOB when the file is extracted from APEX_APPLICATION_FILES, remove the EPA of the problem, and then write in the file system as a CLOB.

    I tried to do by converting the BLOB in a clob, for example with this function:

    A function like this is reinventing the wheel. 10g comes with dbms_lob.convertToClob (see above).

    And after conversion, trying to replace all the occurrences of single line within this clob breaks, for example with this code:

    l_clob := replaceClob(l_clob,chr(10),' ');
    

    Who will replace all the LFs, whether or not they are in CR/LF pairs. Use regexp_replace/regular expressions to exclude EPA following a CR (see above).

    "Without success" means, that the line breaks have not been replaced. I tried several ways as delete (replace without a third parameter and the corresponding function), replacement (for example with a white) etc. !

    I even tried to apply the function of standard replacement for varchars on a clob that I read somewhere that it is supported in 10g and apex 4.1 but with the same result.

    I think that you have been making life difficult for yourself. Everything that seems to involve more (ineffective) writing code as necessary. Everything you need is built into 10g (it seems that you could use the obsolete references?)

    I hope I could explain the question a bit better now and would appreciate it if you had a starting point for me.

    Should have what you need in the above examples.

  • Join the various documents on a single line

    Hello

    How to unite into a single line a result with more than one record?

    That is to say:
    cod_prod     tax     tax_name     value
    1          1     tax1          5
    1          2     tax2          10
    1          3     tax3          8
    2          1     tax1          3
    2          2     tax2          6
    3          1     tax1          6
    4          1     tax1          7
    4          2     tax2          12
    4          3     tax3          6
    4          4     tax4          9
    Back to this:
    cod_prod     tax     tax_name     value     cod_prod     tax     tax_name     value          cod_prod     tax     tax_name     value     cod_prod     tax     tax_name     value
    1          1     tax1          5     1          2     tax2          10          1          3     tax3          8
    2          1     tax1          3     2          2     tax2          6
    3          1     tax1          6
    4          1     tax1          7     4          2     tax2          12          4          3     tax3          6     4          4     tax4          9
    -Oracle Database 11 g Release 11.2.0.1.0 - 64 bit Production
    -OEL 2.6.32 - 100.0.19.el5

    Use 'pivot' which is available in oracle 11g

  • Single line based on two columns and a single column

    Dear members,

    I have a table that contains duplicate rows, for which a request should be able to extract the unique row in the table. Here the unique is not based on a single column, but it should be in two columns and also check on the uniqueness on a column.

    create table addr (varchar2 (10) firstname, lastname varchar2 (10), area varchar2 (3));

    insert into values addr ('bob', 'james', 1');
    insert into values addr ('bob', 'james', 1');

    insert into values addr ('harry', 'bert', ' 1');
    insert into values addr ('jimmy', 'bert', ' 1');

    insert into values addr ('sam', 'mac', '1');
    insert into values addr ('sam', 'Knight', '1');

    insert into values addr ('tom', 'sand', '1');
    insert into values addr ("cat", "mud", "1");


    The query output must contain 3 lines.

    Bob - james
    Harry - bert or jimmy - bert [or the other of them], but not both
    -Mac or sam - Sam Knight [or the other of them], but not both
    Tom - sand
    Cat - mud

    SELECT firstname, lastname as total area WHERE addr = '1' GROUP by firstname, lastname; It takes no duplication of single column...

    Any suggestions...
    SQL> with t_data
    as
    (
    select 'bob' as firstname, 'james' as lastname, '1' as area from dual union all
    select 'bob', 'james', '1' from dual union all
    select 'harry', 'bert', '1' from dual union all
    select 'jimmy', 'bert', '1' from dual union all
    select 'sam', 'mac', '1' from dual union all
    select 'sam', 'knight', '1' from dual union all
    select 'tom', 'sand', '1' from dual union all
    select 'cat', 'mud', '1' from dual
    )
    SELECT
            firstname,
            lastname,
            area
    FROM
            (
                    SELECT
                            t.*,
                            row_number() over(partition BY firstname order by 1) rn,
                            row_number() over(partition BY lastname order by 1) rn1
                    FROM
                            t_data t
            )
    WHERE
            rn     = 1
    AND rn1 =1 ;  
    
    FIRSTNAME       LASTNAME        AREA
    --------------- --------------- ----------
    bob             james           1
    cat             mud             1
    jimmy           bert            1
    sam             knight          1
    tom             sand            1
    
    SQL>
    

Maybe you are looking for