Selection of a specific record from a query


I have been using a certain set of code to query a database for a Recordset:


< CFQUERY NAME = "RandPick" DATASOURCE = "MyDB" >
SELECT ID
FROM MyTable
< / cfquery >


Then, I select randomly 1 number within this number of records:


< CFSET RND_PICK = plageAleatoire (1, #RandPick.RecordCount #) >


Finally, I use STARTROWOPTIONAL to display a field from the selected randomly record (what am I on a flash file):


MyFile.swf? ID = < CFOUTPUT QUERY = "RandPick" StartRowOptional = "" #RND_PICK # "LIGNESMAX ="1"> #PickID # < / CFOUTPUT >"


The final output might look like this:


MyFile.swf? ID = 46


This all works fine, but now I want to do something a little more complicated: I want to take this field value I found (in this case '46') and I want to ask a second table that contains detailed information about ID 46:

< CFQUERY NAME = "DetailedPickInfo" DATASOURCE = "MyDB" >
SELECT ID, PickDescription
OF MySecondTable
Where ID = ' 46 "
< / cfquery >


My problem is that I can't use my STARTROWOPTIONAL trick to incorporate the ID selected in my second request:

< CFQUERY NAME = "DetailedPickInfo" DATASOURCE = "MyDB" >
SELECT ID, PickDescription
OF MySecondTable
Where ID = < CFOUTPUT QUERY = "RandPick" StartRowOptional = "" #RND_PICK # "LIGNESMAX ="1"> ' #PickID # ' < / CFOUTPUT >"
< / cfquery >

Of course, which is not allowed.

Could someone smart please help me find a way to do this?


Basically, I'm trying to select a random record from a query and then JOIN the selected record with a second table (where I want to grab a piece of data).

I understand that my STARTROWOPTIONAL method is a bit of a hack, and there is probably a better way to achieve all this.

Any help would be appreciated.



On a related note, I would also like to know a general solution for the selection (for example) the 5th record a query (or the 32nd of a query)

Thank you

Instead of doing this:

MyFile.swf? ID =#PickID #

Maybe you should set a variable with the value returned by your cfoutput statement, then use this variable as both your setting and picID URL in your second query value. Something like this:

(Note to Azadi: the value of RND_PICK is not the ID value, but the value of the number of records of the line returned by the first query that contains the ID of interest.)

Phil

Tags: ColdFusion

Similar Questions

  • How to display the records from a query in the non-base data field

    Hello

    I have a problem:
    I have a query with a lot of tables and column 6 (select a, b, c, d, e, f x, y, z, t, s, g where the conditions) and I use 3 parameters.
    I create 3 settings: datai,: dataf and: partner and a button with a trigger when the button is pressed.
    Then a create a block manually with six field non-database a1, b1, c1, d1, e1, f1.
    Now, I want to display all the records in my query in a1, b1, c1, d1, e1, f1 where a1 = a, b1 = b, etc. and all the records (if I have 20 record, it will display 20 records in the non-base data field) when I press the button.

    How I did it:
    I create a cursor with the query, and then
    start the open cursor
    loop
    Fetch cursor in: a1,: b1,: c1: d1: e1,: f1;
    end loop;
    close the cursor;
    end;

    It displays a single record in a1, b1, c1 only, and it must display 100 records and date for all fields.

    Can someone help me with this problem?
    Thank you.

    Published by: 928437 on October 1, 2012 02:55

    Creating a view and the query in a database block are a great solution.

    To use the block non-base of data:
    You are missing the most important Next_Record; command.

     Begin
    Go_block('X'); -- block X is the non-database block
    Clear_Block(No_Validate);
    open cursor X1;
    loop
    If :System.Record_status != 'NEW' then
    Next_Record;
    End if;
    fetch X1 into :a1,:b1,:c1,:d1,:e1,:f1;
    Exit when X1%NOTFOUND;
    end loop;
    close X1;
    end;

  • Selection of understanding... from the query timestamp

    Hello

    I'm stuck with this scenario where we offer production data the developer to achieve a purpose test by altering the critical columns of the company by an arbitrary value continues the update statement.

    Now the problem is when we fire select... from the timestamp request, we are able to display the old corrupted data. I created an example test case scenario:

    CREATE TABLE test1 (identification number);

    added values:

    SQL > select * from test1;

    ID

    ----------

    1

    2

    3

    4

    5

    5

    5

    5

    5

    5

    10 selected lines.

    SQL > update test1 ID = 3 where id = 5;

    6 lines to date.

    SQL > commit;

    Validation complete.

    Now the data in the table are:

    SQL > select * from test1;

    ID

    ----------

    1

    2

    3

    4

    3

    3

    3

    3

    3

    3

    10 selected lines.

    Now when I fire from the timestamp query I am able to see old data:

    SQL > select * from test1 from sysdate timestamp - 5/1440;

    ID

    ----------

    1

    2

    3

    4

    5

    5

    5

    5

    5

    5

    10 selected lines.

    SQL > select flashback_on from database v$.

    FLASHBACK_ON

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

    NO.

    SQL > show parameter recyclebin;

    VALUE OF TYPE NAME

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

    Recyclebin OFF string

    Now, I would like to know where oracle recover old data. According to my knowledge, it's going to be fetch these data to undo tablespace If yes then I would like to know is possible to stop this because this could expose the old data of the contracting authority.

    Note:-this isn't a good way to hide the data, but it is a call from management for not no opt data tool because of the license of masking

    You could do a DOF that is not actually change anything:

    orclz > dept desc;

    Name                                                        Null?    Type

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

    DEPTNO NOT NULL NUMBER (2)

    DNAME                                                                VARCHAR2(14)

    LOC                                                                  VARCHAR2(13)

    orclz > alter table dept change (dname varchar2 (14));

    Modified table.

    orclz > select * from the Department as of timestamp(systimestamp-1/24);

    Select * from the Department as of timestamp(systimestamp-1/24)

    *

    ERROR on line 1:

    ORA-01466: unable to read data - table definition has changed

    orclz >

    --

    John Watson

    Oracle Certified MAster s/n

  • Try to get a specific record from an Access database?

    Right, then. So now I've got my select working correctly and started working on the 'Onchange' function

    Can someone tell me why the first ' alert (); "displays correctly and then the following message does not work? Oh the page continues to operate, but no error message or anything else. What I am doing wrong?

    (Microsoft Access, Dreamweaver CS5 and ASP)

    Thank you!

    ================

    < head >

    < script type = "text/javascript" >

    function changeFunc (xx)

    {

    var fred = "select * from houses where ID ='" + xx + "'";

    alert (fred);

    NH. Execute (Fred);

    Alert (Fred);

    }

    < /script >

    < / head >

    ================

    Is a decent tracing/debugging tool available? Obviously, my code is a failure, I want to know why...

    PHP MySQL & are commonly used on Linux / Apache servers.

    MsSQL & ASP.NET are commonly used on Windows servers.

    Dreamweaver CC 2015 is the current version.

    It is much better but in a different way.  Try it free for 30 days see if you wish.

    It is only available by monthly subscription,

    Full throttle, USD $ 49.99/mo or

    Simple App Plan, $19.99 / mo

    Pricing plans and creative Cloud membership | Adobe Creative Cloud

    Nancy O.

  • Delete query to delete records from multiple tables

    All,

    I need a delete query that will delete the records from the tables. Please see the structure of the table & below
    CREATE TABLE TEMP1 (ID NUMBER(10),NAME VARCHAR2(40),CLASS VARCHAR2(40),COLLEGE VARCHAR2(40));
    CREATE TABLE TEMP2 (ID NUMBER(10),CITY VARCHAR2(40),STATE(40));
    
    INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (1000,'SAM','CS','UNIV_1');
    INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (2000,'RIO','CS','UNIV_1');
    INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (3000,'CHRIS','CS','UNIV_1');
    INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (4000,'ALEX','CS','UNIV_1');
    
    INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (1000,'Auburn','NY');
    INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (2000,'Ithaca','NY');
    INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (3000,'Mount Vernon','NY');
    INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (4000,'Port Jervis','NY');
    Now, I need to delete the records in these tables where the ID is '2000' by using a single delete query. Is this possible? This may be a newbie question. Help, please.

    "using a single request deletion. Is this possible?

    Nope.
    You can insert into multiple tables by using a single query, INSERT ALL job, but you cannot delete more than one table using a single query.

  • I need a query that selects the amount of records for each day of a table.

    I need a query that selects the amount of records for each day of a table.
    For example, the result would be:

    1 14 date
    Date 2-3

    etc.

    Any ideas?

    Sort:

    SELECT count ([IDCommentaire]), convert (varchar, dateAdded, 112)

    OF COMMENTSgroup by convert (varchar, dateAdded, 112)

  • Problem in «Insert into...» "Select * from tablename" query

    Hello
    I am inserting a million record from one table to another table using "insert in...". Select * from 'method. During this insertion, if one of the recording have insertion any problem then obiviously, be rollbacked, - not only that, to find the wrong people, the recording will be a tedious job.

    is it possible to find which record having problems during such an insertion? and is it possible to validate the transaction?

    Note: I know that we can use the collection method in bulk to solve this problem, but my situation, I have to use "insert..." Select * from 'method only.

    Please guide me if anyone have dealt with this problem before.

    Thank you
    Kalanidhi

    You can try the ERROR LOG IN the clause of the INSERT statement.

  • Retrieve the random record from SQL and also an ORDER

    I need a query that is able to get X amount of random records from a database of SQL2008, but I also want those results to then order by a field in the same table numberic, camp_priority

    I have

    SELECT TOP #DisplayAmount #, camp_uid, camp_title, camp_text, camp_image_type
    Campaigns
    WHERE camp_uid IN

    etc... etc.

    then, at the bottom, I

    ORDER BY newid (), camp_priority

    The problem seems to be that I'm random records, but it is not ordered by the camp_priority

    Anyone have any ideas?

    Thank you

    Mark

    Hey Adam,.

    I misread your original post, now I see how it was supposed to work, just posted below... got it works... works very well. If all goes well, is not to kill the CPU that this query will use a LOT... I'll just take a plu ;-) CPU

    Regarding the performance of NEWID() issue, I do not have a specific link, I was just hunting around different forums etc and found a few posts that talked about performance issues and who had a command I never saw that took a percentage of files with a lot of perfomance test graphic showing it was 10 times slow the other approach.

    I'll just have to see how it goes

    Thanks for the help

    Mark

  • How to retrieve a single record from access by program?

    I need to recover a single access record. I have two columns, 'Sess' and 'Topic' in my database. I want back the Session number ('Sess') for a particular topic and post it on the front panel. I wrote the attached VI based on an example I found. This VI contains the number of the Session for the first record, but I can't understand how to identify a search for a specific record in the table.  Thank you!

    Do a google search for «sql tutorial» You need to learn how the SELECT statement. The general syntax is:

    SELECT column_name (s)
    Table_name FROM
    WHERE column_name operator value

  • selection of the missing records between 2 duplicity without worrying about tables of records

    Hi all

    I have received_bills and send_bills of 2 tables.

    The SEND_BILLS table is the source table displaying all records in it.

    I need to compare two tables together and insert all the missing elements in received_items including duplicate records.

    There may be duplicate in 2 tables records.

    I wrote a query, but it does not select the duplicate records if it's all the 2 tables. When the same duplicate records are send_bills and received_bill without worrying because send_bills has 4 of them and received_bill 2, it does not select the other 2 duplicate records. And it's just what I need.

    the query is

    SELECT SEND. POINT OF REFERENCE,

    Send. PAYMENT,

    Send. CODE

    OF SEND_BILLS SEND

    WHERE THERE IS NOT (SELECT REC. DATUM, PAYMENT, REC. REC. CODE

    OF RECEIVED_BILLS REC

    WHERE REC. REFERENCE = SEND. SCRATCH CARDS

    AND REC. PAYMENT = SEND. PAYMENT

    AND REC. CODE = SEND. CODE)

    send_bills records

    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1529A3
    OCTOBER 10, 1547A4
    9 OCTOBER 1519A8
    OCTOBER 10, 1520A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5
    OCTOBER 10, 1525A5

    received_bills records

    OCTOBER 10, 1519A1
    OCTOBER 10, 1529A3
    OCTOBER 10, 1547A4
    OCTOBER 10, 1519A1

    the result of the query is:

    OCTOBER 10, 1525A5
    OCTOBER 10, 1525A5
    OCTOBER 10, 1520A1
    9 OCTOBER 1519A8

    So he selects all the records

    the result should be

    OCTOBER 10, 1525A5
    OCTOBER 10, 1525A5
    OCTOBER 10, 1520A1
    9 OCTOBER 1519A8
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1

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

    -The DOF for Table SEND_BILLS

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

    CREATE TABLE SEND_BILLS

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE)

    )  ;

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

    -The DOF for Table RECEIVED_BILLS

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

    CREATE TABLE 'RECEIVED_BILLS '.

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE)

    )  ;

    -Insert the script for send_bills

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 29, 'A3');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('09-OCT-15','DD-MON-RR'), 19, 'A8');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 20, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5')

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5')

    -Insert invoices received from script

    Insert into RECEIVED_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into RECEIVED_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 29, 'A3');

    Insert into RECEIVED_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');

    Insert into RECEIVED_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Can someone please help me with the query so that I can also select all the missing records, including duplicates.

    Thanks in advance.

    Best regards

    Caroline

    If you should by all means use loop and then (send_bills and received_bills contain the same data as your original post):

    Select the reference, payment, code

    of (with

    Duplicator (Datum, Payment, code, CNT) as

    (select the reference, code, payment, cnt - 1).

    from (select datum, payment, code, count (one) - cnt count (two)

    (select date, payment, code, 1 one, to_number (null) two)

    of send_bills

    Union of all the

    Select datum, payment, code, to_number (null), 2 two

    of received_bills

    )

    Reference group, code

    having count (one)! = count (two)

    )

    Union of all the

    Select the reference code, payment, cnt - 1

    The duplicator

    where cnt > 0

    )

    Select the reference, payment, code

    The duplicator

    )

    DATUM PAYMENT CODE
    10/09/2015 19 A8
    10/10/2015 19 A1
    10/10/2015 25 A5
    10/10/2015 20 A1
    10/10/2015 19 A1
    10/10/2015 25 A5

    Concerning

    Etbin

  • records in the query within 24 hours of the table

    Hi gurus of the oracle,.

    I need to get records from the table by using the timestamp of 6 AM (yesterday) data type column to 6 AM (today).

    my query is

    Select * from tota_pt where substr (to_char (tm_stamp,' DD-MM-YYYY hh), 12, 9) between ' 06:00:00 ' 23:59:00 ' and (tm_stamp) trunc sysdate-1 to sysdate;

    Cannot find the logic. Please help me.

    Thank you and best regards,

    REDA

    Is that what you want?

    select *
    from tota_pt
    where tm_stamp between  trunc(sysdate-1)+numtodsinterval(6,'hour') and trunc(sysdate)+numtodsinterval(6,'hour')
    
  • Insert records from a single to two related tables table

    DB - 10G
    OS - XP

    We have thousands of records delimited by commas that we want to insert in a normalized table structure.

    I created a group of test data that can be found at the end of this post.


    I have csv files that look like this;

    Donald, huey
    Dewey, Donald
    Donald, louie

    And I want that data to be inserted into a table separate two like that;

    table named PARENTS
    parent_name PK
    1 donald

    Table named for CHILDREN
    child_name fk PK
    1 1 huey
    1 2 dewey
    1 3 louie


    I built an insert query that looks like this;

    INSERT ALL
    IN parents (parent_id, parent_name) VALUES (parents_seq.nextval, parent_name)
    IN children (children_id, parent_id, child_name) VALUES (children_seq.nextval, parents_seq.nextval, child_name)
    SELECT parent_name, child_name
    SOURCES;

    And this has resulted in the following:

    Table named PARENTS
    PK child_name
    1 DONALD
    2 DONALD
    3 DONALD

    Table named PARENTS
    child_name fk PK
    1 1 HUEY
    2 2 DEWEY
    3 3 LOUIE

    Anyone have any ideas on how I could accomplish this task?

    This is some sample data;

    [code]
    Parents_seq SEQUENCE DROP;
    Sources_seq SEQUENCE DROP;
    Children_seq SEQUENCE DROP;
    Sources of DROP TABLE.
    DROP TABLE children;
    Parents of DROP TABLE;

    CREATE SEQUENCE PARENTS_SEQ MINVALUE MAXVALUE 1 1000000000000000000000000000 INCREMENT OF 1 START WITH 1 CACHE 20 ALL NOCYCLE.

    CREATE THE PARENTS TABLE
    (THE NUMBER (8) OF PARENT_ID NOT NULL)
    PARENT_NAME VARCHAR2 (50 CHAR) NOT NULL,
    CONSTRAINT PARENTS_PK PRIMARY KEY (PARENT_ID)
    );

    create or replace
    PARENTS_BI RELAXATION
    FRONT
    INSERT OR UPDATE PARENTS
    FOR EACH START OF LINE

    IF THE INSERTION

    IF: NEW. PARENT_ID IS NULL THEN
    SELECT PARENTS_SEQ.nextval IN: NEW. PARENT_ID FROM dual;
    END IF;

    END IF;

    END;
    /


    CREATE SEQUENCE SOURCES_SEQ MINVALUE MAXVALUE 1 1000000000000000000000000000 INCREMENT OF 1 START WITH 1 CACHE 20 ALL NOCYCLE.

    CREATE TABLE SOURCES
    (THE NUMBER (8) OF SOURCE_ID NOT NULL)
    PARENT_NAME VARCHAR2 (50 CHAR) NOT NULL,
    CHILD_NAME VARCHAR2 (50 CHAR) NOT NULL,
    CONSTRAINT SOURCES_PK PRIMARY KEY (SOURCE_ID)
    );

    create or replace
    SOURCES_BI RELAXATION
    FRONT
    INSERT OR UPDATE ON SOURCES
    FOR EACH START OF LINE

    IF THE INSERTION

    IF: NEW. SOURCE_ID IS NULL THEN
    SELECT SOURCES_SEQ.nextval IN: NEW. SOURCE_ID FROM dual;
    END IF;

    END IF;

    END;
    /

    INSERT INTO SOURCES (PARENT_NAME, CHILD_NAME) VALUES ('DONALD', 'HUEY');
    INSERT INTO SOURCES (PARENT_NAME, CHILD_NAME) VALUES ('DONALD', 'DEWEY');
    INSERT INTO SOURCES (PARENT_NAME, CHILD_NAME) VALUES ('DONALD', 'LOUIE');
    Commit;


    CREATE SEQUENCE CHILDREN_SEQ MINVALUE MAXVALUE 1 1000000000000000000000000000 INCREMENT OF 1 START WITH 1 CACHE 20 ALL NOCYCLE.

    FAST * CREATE TABLE *.
    CREATE TABLE CHILDREN
    (CHILDREN_ID NUMBER OF NON-NULL
    , PARENT_ID NUMBER NOT NULL
    CHILD_NAME VARCHAR2 (50 CHAR) NOT NULL,
    CONSTRAINT CHILDREN_PK PRIMARY KEY (CHILDREN_ID)
    );

    create or replace
    CHILDREN_BI RELAXATION
    FRONT
    INSERT OR UPDATE ON CHILDREN
    FOR EACH START OF LINE

    IF THE INSERTION

    IF: NEW. CHILDREN_ID IS NULL THEN
    SELECT CHILDREN_SEQ.nextval IN: NEW. CHILDREN_ID FROM dual;
    END IF;

    END IF;

    END;
    /

    [code]

    Looks like it's a way to do this:

    insert into parents (parent_name) select distinct parent_name from sources;
    
    select *
      from parents;
    PARENT_ID              PARENT_NAME
    ---------------------- --------------------------------------------------
    1                      DONALD
    
    insert into children (parent_id, child_name)
    select p.parent_id, s.child_name
      from sources s
      join parents p
        on (s.parent_name = p.parent_name);
    
    select *
      from children;
    
    CHILDREN_ID            PARENT_ID              CHILD_NAME
    ---------------------- ---------------------- --------------------------------------------------
    1                      1                      HUEY
    2                      1                      DEWEY
    3                      1                      LOUIE
    
  • How to generate xml with CDATA from a query

    I have the following query
    with data_tab as ( select 'Geetha' "code" ,'Book' "category" from dual union            
    select 'Nokia' "code" ,'mobile' "category" from dual )
    select Xmltype(cursor(select * from data_tab)) from dual
    and the output is
    <?xml version="1.0"?>
    <ROWSET>
     <ROW>
      <code>Geetha</code>
      <category>Book</category>
     </ROW>
     <ROW>
      <code>Nokia</code>
      <category>mobile</category>
     </ROW>
    </ROWSET>
    but I want to insert ot XML CDATA.
    Is that I need this xml file in the following format.
    <?xml version="1.0"?>
    <ROWSET>
     <ROW>
      <code>![CDATA[Geetha]]</code>
      <category>![CDATA[Book]]</category>
     </ROW>
     <ROW>
      <code>![CDATA[Nokia]]</code>
      <category>![CDATA[mobile]]</category>
     </ROW>
    </ROWSET>
    Please help me on this. In my original query, I am selecting from a record type, and it is nested. So I can not change the query select * from data_tab

    Manjusha Muraleedas wrote:
    Is there another solution.

    Well, Yes and no...

    No, because a CDATA section is supposed to be built directly on the data source, so that the content is preserved as is, with no escaped character.
    Yes, you can transform the XML to add CDATA sections thereafter, but what would be the point? The XMLType constructor already still escaped characters that are not valid.

    Out of curiosity, why do you require CDATA instead of escape sequences?

  • How to delete records from a table that has a composite unique key duplicate

    Hello
    I get the customer data from various sources in the staging of the table where I insert in the database table where the combination of two columns is considered as a unique key. But there is a possibility of duplicates. How to find duplicates in a SQL or pl/sql

    Thank you
    Manoi.

    Kassa,

    You can see the duplicates by using the following query...

    sql> select * from temp_rajesh;
    
          COL1       COL2 MESSAGE
    ---------- ---------- ------------------
           100        200 message
           100        200 message2
           300        400 message3
           400        500 message 4
    
    sql> select col1, col2, count(*)
      2     from temp_rajesh
      3       group by col1, col2
      4         having count(*) > 1;
    
          COL1       COL2   COUNT(*)
    ---------- ---------- ----------
           100        200          2
    

    -If in the case of duplicate records, you should see only the duplicates (according to some timestamp etc., you can use the functinon row_number analytic..)

      1  select col1, col2 from (
      2  select col1, col2,
      3         row_number() over (partition by col1, col2
      4                            order by message) rn
      5    from temp_rajesh)
      6*   where rn > 1
    sql> /
    
          COL1       COL2
    ---------- ----------
           100        200
    

    In the above example, I use message to order, you can replace it with activity_timestamp or the insertd_date according to your logic... when there are two records... one that you choose to duplicate.

    Thank you
    Rajesh.

    Published by: Rajesh Chamarthi on November 20, 2009 12:05 AM (added for example)

  • Little help from the query

    small request I have given as below,




    Month ProductNo CustomerNo units

    9001 1001 Jan - 09 100
    9002 1002 Jan - 09 200
    9003 1003 Jan - 09 300
    Jan 9001 400 ABCCustomer
    9002 1004 Jan - 09 500



    for all record - if column - customerNo starts with digital it must show as CN_ * other wise of the same name.



    Result must be


    9001 100 CN_1001-09 Jan
    9002 200 CN_1002-09 Jan
    9003 300 CN_1003-09 Jan
    Jan 9001 400 ABCCustomer
    9002 500 CN_1004-09 Jan


    Can help get the query

    A logic that is easier to implement this is as below

    SQL> with t as (select 'jan' Month, 9001 ProductNo,'1001-09'  CustomerNo,100 Units from dual union all
      2  select 'jan', 9002, '1002-09', 200 from dual union all
      3  select 'jan', 9003, '1003-09', 300 from dual union all
      4  select 'jan', 9001, 'ABCCustomer', 400 from dual union all
      5  select 'Jan', 9002, '1004-09', 500 from dual)
      6  select month,productno,case when upper(substr(customerno,1,1))=lower(substr(customerno,1,1))
      7  then 'CN_'||customerno else customerno end customerno,units from t;
    
    MON  PRODUCTNO CUSTOMERNO          UNITS
    --- ---------- -------------- ----------
    jan       9001 CN_1001-09            100
    jan       9002 CN_1002-09            200
    jan       9003 CN_1003-09            300
    jan       9001 ABCCustomer           400
    Jan       9002 CN_1004-09            500
    

    TRY WITH THIS upper (substr(customerno,1,1)) = lower (substr(customerno,1,1))

Maybe you are looking for

  • Satellite Pro 6100: keys Fn does not

    Hello Ive got a laptop Satellite Pro 6100. IM of problems using the secondary function keys (I'm not sure what they call them!). When I press the function (Fn) key, the light below the F10 button as it should, but when I press one of the brightness o

  • Qosmio F-15 does not turn on

    Hey all. So I've dealt with a friends Qosimo F15. A long story short, after that I have all done in my knowledge/power lift the computer and works well, that the system is returned to my friend with no sound and bad running. The problem with the soun

  • I need to know how to update my microsoft office and internet explore safely.

    I'm not sure on what are the steps to take when you try to update my windows desktop and are there costs associated with this process. My next question is how can I check if I have the updates for my internet explore.

  • Always ask for help.

    I have asked for help but received none. I have an e machines T6520 in and all of a suddenn I have no audio device. I have no idea where it went and how to get it back. I went to the website of machines e and downloaded audion drivers, then I extract

  • Problem with index of development in the storm

    I'm working on storm 9530 in a form, there are 3 managers as h1, h2, h3 H3 holds n h1, h2 and some focusable label fileds and custom button fields When I try to use h3.getFieldwithFocusIndex) It always returns the value of the h1... Manager component