How select only one line

Hello
I have a select query that returns a couple of lines.
now, I would like for the query to return only one row (the first match it can find).
How do I do that?
Thank you!

my sample of my data as below, the registration of the first and the second is equal and I want the column of the first row and ignore the second row.


9410 20110812 84A8E46E8C97
9420 20110813 84A8E46E8C97
84A8E46E8C6E 20110816 9410
9400 20110819 84A8E46E8AFA

You can try

  SELECT msid, bsid, starttime
    FROM (SELECT msid, bsid, starttime, ROW_NUMBER () OVER (PARTITION BY msid ORDER BY msid, starttime) rn FROM aaa_bill)
   WHERE rn = 1
ORDER BY 1, 3

Tags: Database

Similar Questions

  • Link from Oracle to MySQL database select only one line

    Hello

    I created a connection to the batabase Oracle 11.2 to a MySQL database via a database link. The following statement shows that 35 lines are in the mySQL table:

    SQL > select count (*) from 'main_pages"@MOREWEB;

    COUNT (*)

    ----------

    35

    But a normal select statement only return 1 row.

    SQL > select 'subject' of 'main_pages"@MOREWEB;

    Object

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

    Übersicht: references

    I use the mysql-connector-odbc driver - 3.51.30 - winx64. One is the newer version be installed because on Windows Server 2008 R2, I get an error with a missing dll file. The DataDirect ODBC driver is not possible, because we like to use the MySQL-database free one only support for DataDirect enterprise edition.

    I have also tried to limit the HS_OPEN_CURSORS or do not limit the HS_FDS_FETCH_ROWS, but there is no difference in the result. I always get only one line.

    HS Init.ora

    # This is an example of initialization file of the agent that contains the HS settings

    # necessary for the database to ODBC gateway

    #

    # HS init parameters

    #

    HS_FDS_CONNECT_INFO = moreweb

    HS_FDS_TRACE_LEVEL = WE

    HS_FDS_FETCH_ROWS = 1

    #

    # Required for the non-Oracle system environment variables

    #

    #set < varenv > = < value >

    HS trace file

    Oracle Corporation - MITTWOCH 5 November 2014 13:56:22.066

    Heterogeneous Agent release

    11.2.0.1.0

    Oracle Corporation - MITTWOCH 5 November 2014 13:56:22.066

    Version 11.2.0.1.0

    HOSGIP to 'HS_FDS_TRACE_LEVEL' returned 'ON '.

    HOSGIP to 'HS_OPEN_CURSORS' returned '50 '.

    HOSGIP to 'HS_FDS_FETCH_ROWS' returned '1 '.

    HOSGIP for "HS_LONG_PIECE_TRANSFER_SIZE" returned "65536".

    HOSGIP to 'HS_NLS_NUMERIC_CHARACTER' returned '. "

    HOSGIP to 'HS_KEEP_REMOTE_COLUMN_SIZE' returned 'OFF '.

    HOSGIP for "HS_FDS_DELAYED_OPEN" returns 'TRUE '.

    HOSGIP to 'HS_FDS_WORKAROUNDS' returned '0 '.

    HOSGIP to 'HS_FDS_MBCS_TO_GRAPHIC' returned 'FALSE '.

    HOSGIP to 'HS_FDS_GRAPHIC_TO_MBCS' returned 'FALSE '.

    HOSGIP to 'HS_FDS_RECOVERY_ACCOUNT' returned 'RECOVER '.

    HOSGIP for "HS_FDS_TRANSACTION_LOG" returns "HS_TRANSACTION_LOG".

    HOSGIP to 'HS_FDS_TIMESTAMP_MAPPING' returned 'DATE '.

    HOSGIP to 'HS_FDS_DATE_MAPPING' returned 'DATE '.

    HOSGIP to 'HS_FDS_CHARACTER_SEMANTICS' returned 'FALSE '.

    HOSGIP for "HS_FDS_MAP_NCHAR" returns 'TRUE '.

    HOSGIP to 'HS_FDS_RESULTSET_SUPPORT' returned 'FALSE '.

    HOSGIP to 'HS_FDS_RSET_RETURN_ROWCOUNT' returned 'FALSE '.

    HOSGIP to 'HS_FDS_PROC_IS_FUNC' returned 'FALSE '.

    HOSGIP to 'HS_FDS_REPORT_REAL_AS_DOUBLE' returned 'FALSE '.

    using mpgw as the default value to "HS_FDS_DEFAULT_OWNER".

    HOSGIP to 'HS_SQL_HANDLE_STMT_REUSE' returned 'FALSE '.

    SQL text of hgopars, id = 1, len = 36...

    45 00: 53454 C 43542043 4F554E54 282 HAS 2920 [COUNT (*) SELECT]

    10: 46524F4D 20606D 61 696E5F70 61676573 [FROM ' main_pages]

    20: 60204131 [' A1]

    Delayed open until the first fetch.

    Deferred execution open.

    SQL text of hgopars, id = 1, len = 40...

    45 00: 53454 C 43542041 312E6073 75626 has 65 [SELECT A1.' subje(1)]

    10: 63746020 46524F4D 20606D 61 696E5F70 [ct' FROM ' main_p]

    20: 61676573 60204131 [ages A1]

    Delayed open until the first fetch.

    Deferred execution open.

    Please can someone help me.

    Thank you.

    Bianca

    Bianca,

    Everything I've read on this point to a need to install/reinstall the Microsoft Visual C++ Redistributable Package for windows OS 2008.

    You will need to download the appropriate version for your microsoft form system.  There is a lot of information on this topic.  Just

    search on the web, and it should help you in the right direction.

    Thank you!
    Matt

  • need to get only one line when you use between (date columns)

    Hi all

    create the table SAMPLE_ITEMS

    (ITEM_NO, varchar2 (10))

    Date DELIVERY_DATE,

    Number of QTY_SUM1

    Number of QTY_SUM2

    Number ITEM_QTY,

    Number ORDER_QTY,

    Number ITEM_AMOUNT,

    Number of SALES_AMOUNT

    );

    insert into SAMPLE_ITEMS values ('AAA', ' 28 / 04/2014 ',-88, 0,475,262,-123.45,-1188);

    insert into SAMPLE_ITEMS values ('AAA', ' 28 / 05/2014 ', 0, - 122, 475, 262, - 10.234,-1647);

    insert into SAMPLE_ITEMS values ('AAA', ' 16 / 06/2014. ', 0, 0,475,262,-80.59,-135);

    insert into SAMPLE_ITEMS values ('AAA', 19 December 2014 ', 0, 0,475,262,-42.29,-67.5);

    Setting out with my own query,

    ITEM_NOTRUNC (DELIVERY_DATE)QTY_SUM1QTY_SUM2ITEM_QTYORDER_QTYITEM_AMOUNTSALES_AMOUNT
    AAA28/04/2014-880475262-123.45-1188
    AAA28/05/20140-122475262-10.234-1647
    AAA16/06/201400475262-80.59-135
    AAA19/12/201400475262-42.29-67.5

    Every time I question as code

    Select * from SAMPLE_ITEMS

    where DELIVERY_DATE between April 28, 2014 ' and 19 December 2014 '-> they must pass as a parameter

    I need to get only one line

    AAA-88-122475262-256.564-3037.5

    Database 11.2.0.1.0

    Note; Please do not use MAX for Date and do not want to display Date columns in the result

    Note 1: I want to choose DELIVERY_DATE in select it also and only get a line like above the expected result

    SELECT item_no

    SUM (qty_sum1),

    SUM (qty_sum2),

    SUM (DISTINCT item_qty),

    SUM (DISTINCT order_qty),

    SUM (item_amount),

    SUM (sales_amount)

    OF SAMPLE_ITEMS

    WHERE the DELIVERY_DATE BETWEEN TO_DATE (28 April 2014 ', "dd/mm/yyyy")

    AND TO_DATE (19 December 2014 ', "dd/mm/yyyy")

    GROUP BY item_no;

    I will get

    ITEM_NO Trunc (DELIVERY_DATE) QTY_SUM1 QTY_SUM2 ITEM_QTY    ORDER_QTY TTEM_AMOUNT SALES_AMOUNT        

    AAA             12/19/2014                         -88                 -122                475                262                       -256.564              -3037.5

    OK fine, I want to choose DELIVERY_DATE as if so I'll have all the lines, but I want to only show one as shown above

    Because I do report discoverer in Oracle Apps, without taking the DELIVERY_DATE of the select query, it is not possible to move the date as a parameter

    Can you please help me how to do this?

    Thank you

    Post edited by: Rajesh123 NOTE added in the body of the Message

    Post edited by: added test Rajesh123 messages

    Maybe you want a single line in all cases

    Select si.item_no,

    start_date min (d.start_date),

    min (d.end_date) end_date,

    min (si.qty_sum1) qty_sum1,

    min (si.qty_sum2) qty_sum2,

    min (si.item_qty) item_qty,

    min (si.order_qty) order_qty,

    Sum (si.item_amount) item_amount,

    Sum (if. Sales_Amount) sales_amount

    of (start_date select to_date(:date_from,'dd-MON-yyyy'))

    to_date(:date_to,'dd-mon-yyyy') end_date

    of the double

    ) d

    left outer join

    TR sample_items

    on the si.delivery_date between d.start_date and d.end_date

    Group of item_no

    ITEM_NO START_DATE END_DATE QTY_SUM1 QTY_SUM2 ITEM_QTY ORDER_QTY ITEM_AMOUNT SALES_AMOUNT
    - 01/01/1900 31/12/2000 - - - - - -

    Concerning

    Etbin

  • table is expected to insert only one line

    Hi all

    my need is to create the table that allows to insert only one line.

    How can I make it?

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    PL/SQL Release 11.2.0.1.0 - Production

    "CORE 11.2.0.1.0 Production."

    AMT for Linux: Version 11.2.0.1.0 - Production

    NLSRTL Version 11.2.0.1.0 - Production

    Hello

    2621671 wrote:

    Hi all

    my need is to create the table that allows to insert only one line.

    How can I make it?

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    PL/SQL Release 11.2.0.1.0 - Production

    "CORE 11.2.0.1.0 Production."

    AMT for Linux: Version 11.2.0.1.0 - Production

    NLSRTL Version 11.2.0.1.0 - Production

    You can create a unique Index based on a function, like this:

    CREATE UNIQUE INDEX table_x_u ON table_x (NVL2 (col_1, 1, 1));

    You can use any column of any data type.  In other words, the function may return a NUMBER, if the column referenced in the function is a NUMBER.

    Regardless of whether the column is NULL or not; not more than 1 rank is authorized.

  • Help with the query to select only one record from the result set in double

    Hello

    Please help with the query. Version of Oracle database we use is 10g R2.

    I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec

    ID
    Org
    DF
    Sec Sub-Sec

    (163)CQCPDMCPDMHD(163)PCENGENGENG(163)CQASICASICIS8888TSTACTACTAC(163)TSHEHESW6789CQINFOINFOFOS6789PCSECSYSSECSYSINFO16789TSSECSYSSECSYSINFO29009PCBMSBMSBMS1

    My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.

    ID
    DSB

    DF
    SEC
    Sub-Sec
    (163)CQCPDMCPDMHD8888TSTACTACTAC6789CQINFOINFOFOS9009PCBMSBMSBMS1


    Thank you

    Orton

    Hello

    This sounds like a job for ROW_NUMBER:

    WITH got_r_num AS

    (

    SELECT id, DSB, df, s, sub_sec org

    ROW_NUMBER () OVER (PARTITION BY ID.

    ORDER BY org

    ) AS r_num

    OF view_x

    )

    SELECT id, DSB, df, sub_sec s,

    OF got_r_num

    WHERE r_num = 1

    ;

    He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data.  (I know that you said that you were a view selection.  Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.  (I didn't quite understand the explanation above.  I don't know why you want to

    ID ORG DF DRY SUB_SEC

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

    1234 CQ DPRK DPRK HD

    and is not

    1234 IS CQ ASIC, ASIC

    or

    TS 1234 IT IT SW

    or

    1234 CQ ASIC ASIC HD

    )
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Merge only one line on several lines

    I need prepare a merge statement that merge only one line in a table. Here is the table definition, data instruction and fusion sample, I used.
          CREATE TABLE Mob_Attr (NAME VARCHAR2(20), ATTR_1 VARCHAR2(20), ATTR_2 VARCHAR2(20), ATTR_3 VARCHAR2(20));
          CREATE TABLE Mob_Desc (NAME VARCHAR2(50), ATTR_1 VARCHAR2(20), ID NUMBER(20));      
          CREATE TABLE Mob_Main (NAME VARCHAR2(20), ATTR VARCHAR2(20), ID VARCHAR2(10));     
          
          insert into Mob_Attr(name, attr_1, attr_2,attr_3) values ('n1','aa',null,null);
          insert into Mob_Attr(name, attr_1, attr_2,attr_3) values ('n2','bb',null,null);
          insert into Mob_Attr(name, attr_1, attr_2,attr_3) values ('n3','cc',null,null);
          insert into Mob_Attr(name, attr_1, attr_2,attr_3) values ('n4','dd',null,null);
          
          insert into Mob_Desc (NAME,ATTR_1,ID) values ('n1','aa',10);
          insert into Mob_Desc (NAME,ATTR_1,ID) values ('n1','aa',15);
          insert into Mob_Desc (NAME,ATTR_1,ID) values ('n1','aa',123);
          insert into Mob_Desc (NAME,ATTR_1,ID) values ('n1','aa',1455);
          insert into Mob_Desc (NAME,ATTR_1,ID) values ('n2','bb',455);
          insert into Mob_Desc (NAME,ATTR_1,ID) values ('n2','bb',135);
          insert into Mob_Desc (NAME,ATTR_1,ID) values ('n3','cc',15);
          insert into Mob_Desc (NAME,ATTR_1,ID) values ('n3','cc',52);
          insert into Mob_Desc (NAME,ATTR_1,ID) values ('n4','dd',1455);
          
          merge into Mob_Main ma using
          (select d.name, d.attr_1,d.id from Mob_Attr a, Mob_Desc d
          where a.name = d.name and a.attr_1 = d.attr_1
          ) q on (ma.name=q.name and ma.attr=q.attr_1)
          when not matched then
          insert (NAME,ATTR,ID)
          values (q.name,q.attr_1,q.ID);
          
    Merge statement above will actually merge complete data. But I want that the first line will only get inserted to the base table (Mob_Main). If we take the "n1" name first row in the table with the ID Mob_Desc '10' should get only inserted. I go for a cursor to do what I have given huge volume, I prefer the merger instead.
    MERGE INTO Mob_Main ma
         USING (
                  SELECT distinct d.name, d.attr_1, first_value(d.id) over (partition by d.name, d.attr_1 order by d.rowid) id
                  FROM Mob_Attr a, Mob_Desc d
                  WHERE a.name = d.name AND a.attr_1 = d.attr_1
                 ) q
            ON (ma.name = q.name AND ma.attr = q.attr_1)
    WHEN NOT MATCHED
    THEN
       INSERT     (NAME, ATTR, ID)
           VALUES (q.name, q.attr_1, q.ID);
    COMMIT;
    
    select *
    from Mob_Main
    order by name, id;
    
    NAME                 ATTR                 ID
    -------------------- -------------------- ----------
    n1                   aa                   10
    n2                   bb                   455
    n3                   cc                   15
    n4                   dd                   1455      
    
    4 rows selected.
    
  • Is it possible to select only one column of a table for the redaction?

    Hi, converted a Word doc with a table in PDF format.  You will need to write a single column of the table.

    Is it possible to select only one column for the redaction?  When we select and drag downwards, it selects the other columns in the following lines.

    With the help of Acrobat X Pro.  Any help is appreciated.

    Hold down the CTRL key and drag a selection.

  • Cannot select only one column in a double-column PDF

    See the following pdf file example. I can't select a single column. Whenever I have select several lines, I will have two columns. I currently solve this problem by converting the PDF into an image file and load into Acrobat and OCR on it. But this isn't an ideal solution. I wonder if there is a better solution to fix the pdf file so that I can select only one column at a time.

    https://sites.Google.com/site/sharedacrobat/data/double_column.PDF?attredirects=0 & d = 1

    Use Acrobat Pro to tag a PDF file.

    Look at this PDF file:

    http://www.Adobe.com/content/dam/Adobe/en/DevNet/PDF/PDFs/PDF32000_2008.PDF

    to determine what the appropriate marking is, else "smile, be happy" can become remote.

    Look over article 14.

    Alternatives:

    --| Use Acrobat Pro to add tags to the Document. Does Acrobat to make a "best estimate" for marking. OK for a simple PDF content. not ok for other than simple.

    Use a copy of the PDF test to determine if it meets your needs.

    --| If the file creation supports establishing a logical hierarchy of command content (via the built-in tags, titles and styles) and has a proper Tag for output Tagged PDF management then the majority of the work tag can be done from the outset. Creating applications that are 'good things' - FrameMaker, InDesign, Open Office and MS Word.

    There will always be a need to do some post processing with Acrobat Pro.

    If you have InDesign; See:

    http://blogs.Adobe.com/accessibility/2009/07/indesign_accessibility_best_pr.html

    http://www.Adobe.com/accessibility/products/InDesign/

    http://TV.Adobe.com/watch/accessibility-Adobe/preparing-InDesign-files-for-accessibility

    You will notice that the emphasis on tutorials for 'PDF containing the tag' is mainly for 'Accessible PDF'. Accessible PDF is one of the facilities provided by the tag PDF.

    Another is the export of PDF contents in other applications while maintaining the format/layout in the export. A file PDF containing the tag with a well-trained tree not only supports accessibility, it also supports cut/copy - paste & export of content.

    Other tutorials "Accessible PDF" are available on Adobe TV and the Learning Center community user Acrobat.

    http://acrobatusers.com/learning_center

    Be well...

  • HW 2 get the value to select only one option selected by the user in the bean support

    IAM using the select only one option button that is filled during execution.

    I want to get the value selected by the user of a choice selection in the bean to support for other operations of... .IAM using this method, but I got a null pointer exception.

    Public Sub test (ValueChangeEvent tokenChange)
    {
    Integer tokenIndex = (Integer) tokenChange.getNewValue ();
    DCIteratorBinding tokenListIter is getBindings1 () .findIteratorBinding ("TokenIDVOIterator");. in this line null pointer exception
    Token of the line = tokenListIter.getRowAtRangeIndex (tokenIndex.intValue ());
    currenttoken = (Number) token.getAttribute ("TokenId");
    System.out.println ("token ID selected:" + currenttoken);

    }

    I want to know if there is any method to get the value of the value selected by the user to select a choice...

    pls help? //

    3 words:

    "research on the forum.

    asked and answered countless times.

  • Subtotals - delete if there is only one line?

    I'm sure I know the answer to that, but is there a way of subtotals to remove if there is only one line? It doesn't seem to be any documented to do this, but I wonder if anyone has found a kind of workaround...? ... Registry entry?

    I am using Desktop, verision 10.1.2.2

    Thank you!

    Hello
    There is no global setting, but you can remove them on a basis of total per total.

    You change the total and check the box that says do not appear in total for a single line, but like I said you need to do this on a basis of total per total.

    Best wishes
    Michael

  • How can you make boxes select only one?

    I work on the lock to a registration form. There are a few sections with several check boxes, but only one can be marked. We will not accept the form even if there is more than one option marked. Most of the sections there are two boxes, check a box, but not the other. There is a section that has 16 boxes, and Yes only can be marked.  Can I do this?

    Similarly, I also do the same with two text fields, one must be filled.

    Thank you!

    It's easy with checkboxes: give them the same name but different export

    values.

    Not that easy with text fields. You will need to understand how you want

    to work. Other fields must be locked when a field is filled, and

    then unblocked when it's still once empty? They are all would remain editable,

    But if you meet one of them others reset?

    All this must be done with scripts.

  • How to add asterics to line when an item in the line splits into two and only one line display.

    
    
    

    Here, the title is a bit confusing, I completely realize that but here's what I'm trying to accomplish. I have a table with a column that repeats.

    the table looks like this.

    create table testCheck (check_num varchar2(20), amount number(17,2), invh_Code varchar2(20))
    
    

    and it contains data as follows

    INSERT INTO "TESTCHECK" (CHECK_NUM, AMOUNT, INVH_CODE) VALUES ('001', '50', '1123')
    INSERT INTO "TESTCHECK" (CHECK_NUM, AMOUNT, INVH_CODE) VALUES ('001', '50', '1123')
    INSERT INTO "TESTCHECK" (CHECK_NUM, AMOUNT, INVH_CODE) VALUES ('002', '100', '1234'
    
    

    I would like to write a query that would give me of the separate check_num, but put an asterisk on the elements that are in fact double.

    so in other words expected result in this case is as follows.

    "CHECK_NUM" "AMOUNT" "INVH_CODE"
    "001*" 50 "1123"
    "002" 100 "1234"
    

    I could go as far as getting unique values, but what I can't do, it is understand for the life of me how to put the asterisk in there.

    Here's my query.

    with Checkquery as (         
    SELECT  count(*) over (partition by CHECK_NUM order by CHECK_NUM ROWS UNBOUNDED PRECEDING ) thiscount, CHECK_NUM,  AMOUNT,  INVH_CODE
    FROM  TESTCHECK
    group by
    check_num,
    AMOUNT,
    INVH_CODE)
    select check_num, amount,invh_Code from Checkquery where thiscount ='1';
    
    

    can someone tell me please in the right direction. I just want to identify the dups put an asterisk on the record and then only select records.

    According to your last post, you keep what is displayed for the other columns, so why display them at all, so this will do the job.

    SELECT check_num.

    Decode (to_char (Count (*)), '1', NULL,'* ') dup_checks

    TO define by test

    GROUP BY check_num;

    If you want to view the other columns, you have two choices. You must either put some sort of aggregate function in the list of selection, such as min, max, or sum, or they need to be part of the group.

    Concerning

    André

  • How to display the option - Select - for programming select only one option?

    Hi Experts ADF,

    JDEV 11.1.1.4.0

    Hello

    If the LOV is created as below, I get no "- SelectItem -". So any suggestions on how to show that. Sub elements LOV are picked on f: selectItems.

    < af:column sortProperty = "#{bindings." UniquerowlovView1.hints.UniId.name}.

    filterable = "true" sortable = "true".

    headerText = "#{bindings." UniquerowlovView1.hints.UniId.label}.

    ID = "c1" >

    < af:selectOneChoice value = "#{row.bindings.UniId.attributeValue} '"

    autoSubmit label = "#{row." Bindings.UniId.label}' = 'true '.

    required = "#{bindings." UniquerowlovView1.hints.UniId.mandatory}.

    shortDesc = "#{bindings." UniquerowlovView1.hints.UniId.tooltip}.

    ID = "soc1" >

    < f: selectItems value = "#{viewScope.MyBean.associatedCommodityItemList}" id = "vebm_si20" / > "

    < / af:selectOneChoice >

    < / af:column >

    Thank you

    Animesh

    Try this

     
    
                              filterable="true" sortable="true"                           headerText="#{bindings.UniquerowlovView1.hints.UniId.label}"                           id="c1">
    
                      
    
                                          label="#{row.bindings.UniId.label}" autoSubmit="true"
    
                                         required="#{bindings.UniquerowlovView1.hints.UniId.mandatory}"
    
                                         shortDesc="#{bindings.UniquerowlovView1.hints.UniId.tooltip}"
    
                                          id="soc1">
    
                    id="si14" itemLabel="--Select--"/>
    
                      
                      
                    
    

    Ashish

  • Get only one line for each type of a column

    Hello!
    I have a little problem.

    I have a table with 10 columns. One of them has repeated values. My goal is to get all the lines with this column only once for each values he holds.

    Ex:

    Col1 Col2 Col3
    A A A A
    B B B
    C A C
    D C D


    Column 2 has repeated values. My goal is to get:

    A A A A
    B B B
    D C D

    Only once each value in column 2.

    Thank you guys! ;)
    SQL>  CREATE TABLE Tbl (col1 VARCHAR2(1),col2 VARCHAR2(1),col3 VARCHAR2(1));
    
    Table created.
    
    SQL> INSERT INTO Tbl VALUES ('A','A','A');
    
    1 row created.
    
    SQL>              INSERT INTO Tbl VALUES ('B','B','B');
    
    1 row created.
    
    SQL>              INSERT INTO Tbl VALUES ('C','A','C');
    
    1 row created.
    
    SQL>              INSERT INTO Tbl VALUES ('D','C','D');
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> SELECT * FROM tbl t1
      2  WHERE
      3  rowid=(SELECT min(rowid)
      4         FROM tbl t2
      5         WHERE t1.col2=t2.col2);
    
    C C C
    - - -
    A A A
    B B B
    D C D
    
    SQL> SELECT * FROM tbl t1
      2  WHERE
      3  rowid=(SELECT max(rowid)
      4         FROM tbl t2
      5         WHERE t1.col2=t2.col2);
    
    C C C
    - - -
    B B B
    C A C
    D C D
    

    Published by: Johan August 3, 2010 01:31

  • Select only certain lines

    Hi all

    As a result, I have a query with more than 500 lines. I wish only show the first 50 lines. Did you know that any way to prepare the select sentence to do? I prefer to avoid using cursors to do this.

    Kind regards
    dbajug

    Hello

    Use the keyword ROWNUM to pick the first 50 rows

    simplest example

    Select * from EMP
    where rownum< 5="">

    concerning
    Hitesh

Maybe you are looking for