Find the matching record better

create table data(item_no int,item_size varchar2(10),color varchar2(10));

insert into data values (1,null,null);

insert into data values (1,'small',null);

insert into data values (1,null,'pink');

insert into data values (1,'large','red');

create table filters(item_no int,item_size varchar2(10),color varchar2(10),comments varchar2(100));

insert into filters values (1,null,null,'all sizes and colors');

insert into filters values (1,'small',null,'small comment');

insert into filters values (1,null,'pink','love pink');

insert into filters values (1,'large','red','large red comment');

select
d.item_no,d.item_size,d.color,f.comments
from data d,filters f
where d.item_no=f.item_no(+)
and d.item_size = f.item_size(+)
and d.color = f.color(+);

How would I go about matching records in the data table with the best matching filter table record? Best way where the majority of the attributes match (item_no, item_size and color). I thought a simple outer join would, but it does not quite what I need.

What Miss me? Thank you

Hello

Thanks for posting the sample data.

Don't forget to post the exact results you want from these data.

One thing you can do is a Top - N query, like this:

WITH got_r_num AS

(

SELECT d.item_no, d.item_size, d.color, f.comments - or other

ROW_NUMBER () (PARTITION BY d.ROWID - OR primary key,

IN CASE of ORDERS WHEN d.item_no = f.item_no THEN 1 END ELSE 0

+ CASE WHEN d.item_size THEN 1 END ELSE f.item_size = 0

+ CASE WHEN d.color THEN 1 END ELSE f.color = 0

--+... If you have other attributes

/ / DESC

) AS r_num

DATA d

CROSS JOIN filters f

)

SELECT item_no, item_size, color, comments

OF got_r_num

WHERE r_num = 1

;

I would like a unique identifier to each table, and I had want to display in the results.

Remember, in SQL if x or y is NULL then

x = y

won't be TRUE.  If you want NULL in two tables to match anything in the other table, then the same general approach will work, but it is messier.

What results do you want to tie (i.e. for a given line in d, 2 or several lines of f have exactly the same number of corresponding attributes)?

If this number is 0?

Tags: Database

Similar Questions

  • Find close matched record

    I have data in the report_date column and dates are met like this:

    report_date
    01/01/1990
    01/03/1990
    01/04/2000
    12/05/2000
    01/01/2010
    01/02/2010

    Now I want to select a date in the table which is < = date provided by the user but the query must return only the single record. For example, if the user provides 01/01/1997 query should return 01/03/1990, which is < = 01/01/1997 and closer to 01/01/1997.

    If I use WHERE the report_date < = 01/01/1997, then the query returns two records. Y at - it a function or a way to find the closest record matching? Similarly, if the user provides on 01/12/1988 and because there is no available record who has report_date < = 1988-12-01, then it must return more closest date of 01/01/1990.

    Published by: skas on sept 17, 2012 16:39


    SELECT MIN (RD) AS REPORT_DATE OF
    (SELECT MAX (REPORT_DATE) AS RD FROM MY_TABLE
    <=>
    UNION ALL
    SELECT MIN (REPORT_DATE) FROM MY_TABLE
    WHERE REPORT_DATE > USER_GIVEN_DATE);

  • Using SQL to ensure the matching records are mutually exclusive.

    There are two tables defined in the following way:

    Table A

    Number 1

    Number 2

    Date

    ROWID

    Table B

    Number 1

    Number 2

    Date

    Identifier of the line

    Each table stores a call between number 1 and 2 on a specific date. The goal is to map exactly one entry of table A with exactly the record in table B

    in a mutually exclusive way. So a single call to a table must be associated with exactly one call the other table (the key is here

    A.Number1 is B.Number1 and A.Number2 = B.Number2). Because it is a relationship is many to many (the number of source and destination may be paired multiple)

    (time), I'm not able to build a series of sql statements that will allow me to get a relationship one between pairs of telephone numbers.

    I'm not allowed to develop a PL/SQL procedure, which would easily solve this problem.

    I was able to find a solution using MIN(Number 1) KEEP (DENSE_RANK FIRST ORDER BY Date) to THE (PARTITION BY x) the form x

    using temporary tables, which allows me to reach a breaking successively much many relationships (i.e. three broken bones in a 01:58 after

    an iteration, and after one iteration, I arrive at a one to one relationship). However, I can't break these relations some n number of times because it requires number n

    hard curls. Therefore, I need a sophisticated solution that will allow me to achieve a relationship one by one.

    Example of

    Table A

    Record 1

    Number 1:451923456789

    Number 2:541969432045

    Date: 29/07/2015-09:01

    Worksheet 2

    Number 1: 451923456789

    Number 2: 541969432045

    Date: 29/07/2015-09:03

    Table B

    Record 1

    Number 1: 451923456789

    Number 2: 541969432045

    Date: 29/07/2015-09:04

    Worksheet 2

    Number 1: 451923456789

    Number 2: 541969432045

    Date: 29/07/2015-09:05

    If we unite our table A and B by A.Number1 = B.Number1 and A.Number2 = B.Number2, we have 4 records. I'm looking for exactly two records.

    The criteria is to associate by the minimum of the sum of the date of the table A table B date. Therefore, the final result should match:

    (1) record 1 of table A with record 1 of table B.

    sheet 2) 2 table A with 2 record in table B.

    So we must do something to reduce the 4 records resulting from the join of two records describe as we see above.

    The result of the join:

    1st row: TableA.Record1 with TableB.Record1

    2nd place: TableA.Record1 with TableB.Record2

    Rank 3: TableA.Record2 with TableB.Record1

    4th place: TableA.Record2 with TableB.Record2

    What I'm looking for, which is easily achievable with a slider, but not with SQL:

    1st row: TableA.Record1 with TableB.Record1

    4th place: TableA.Record2 with TableB.Record2

    Note that if the minimum date condition allows us to select the necessary records, we won't get the expected results. In other words, using the minimum date.

    the results will be:

    1st row: TableA.Record1 with TableB.Record1

    Rank 3: TableA.Record2 with TableB.Record1

    (criteria - table a minimum date)

    or

    1st row: TableA.Record1 with TableB.Record1

    2nd place: TableA.Record1 with TableB.Record2

    (criteria - date minimum table B)

    Two of these results to break the rule are mutually exclusive.

    Post edited by: 3000640

    If I understand correctly, something like:

    SQL > with tableA (id, telephone1, telephone2, call_date) as)

    2. Select 1, ' 451923456789 ', ' 541969432045',

    3 to_date (July 29, 2015 09:01 ', 'dd.mm.yyyy hh24')

    4 union double all the

    5. Select 2, ' 451923456789 ', ' 541969432045',

    6 to_date (July 29, 2015 09:03 ', 'dd.mm.yyyy hh24')

    double 7),

    TableB 8 (id, telephone1, telephone2, call_date) as)

    9. Select 1, ' 451923456789 ', ' 541969432045',

    10 to_date (July 29, 2015 09:04 ', 'dd.mm.yyyy hh24')

    11 double Union all the

    12. Select 2, ' 451923456789 ', ' 541969432045',

    13 to_date (July 29, 2015 09:05 ', 'dd.mm.yyyy hh24')

    14 double)

    15 select a.id help, a.phone1 aphone1, a.phone2 aphone2,

    16 a.call_date acall_date, b.id offer, b.phone1 bphone1,

    17 b.phone2 bphone2, b.call_date bcall_date

    18 (select id, telephone1, telephone2, call_date,

    19 row_number() over (partition by numbers1, telephone2

    RN 20 order by call_date)

    tablea 21) a

    22 join (select id, telephone1, telephone2, call_date,

    23 row_number() over (partition by numbers1, telephone2

    RN 24 order by call_date)

    tableb 25) b

    26 on a.phone1 = b.phone1 and

    27 a.phone2 = b.phone2 and

    28 a.rn = b.rn;

    HELP APHONE1 APHONE2 ACALL_DATE BPHONE1 BPHONE2 BCALL_DATE OFFERS

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

    1 451923456789 541969432045 July 29, 2015 09:01 1 451923456789 541969432045 July 29, 2015 09:04

    2 451923456789 541969432045 July 29, 2015 09:03 2 451923456789 541969432045 July 29, 2015 09:05

    John

  • Can not find the statistical record of free cell

    When I play Free Cell, at the end of the game, Windows 7 can not find the statistics file to save the results of the games which causes the game to break off and restart. I tried to remove free cell and restore without success. Can I replace the statistical record?

    I think that the statistics are stored in:

    C:\Users\\Appdata\Local\Microsoft Games\Freecell\Freecellsettings.xml

  • Where can I find the sound recorder files?

    * Original title: sound files recorder

    I'm really looking for someone to help me on the extraction of a file of the sound recorder, I wasn't able to save. I use windows 8.

    I tried to look for him C:\Users\James\AppData\Local\Temp for an ART_tmp file, but I couldn't find

    it.

    I tried to play the sound recorder, while I'm looking at the C:\Users\James\AppData\Local\Temp and the ART_tmp appears, but once I close the program without saving it, it will disappear.

    Anyone, where does go... greatly appreciate any help. again, I use Windows 8...

    Thank you

    James L.

    I had this same problem and found the answer here:

    http://www.surfacetablethelp.com/2014/01/Windows-8-1-sound-recorder-file-location-and-best-apps.html

    I find my record and moved to another folder.  It's a m4a file so it works then very easily through my music app

  • HOW CAN I FIND THE MATCHING CODE FOR LEXMARK PRO 805

    How can I find the pairing code for a printer Lexmark 805 purpose multi pro?

    Contact Lexmark support.

  • Find the first record starting with the largest capacity

    Hello

    This question might have been asked before, but I don't know how to describe it in the search field.

    There are 3 drives with 2 fields (id, name). These recordings are:
    1, Amsterdam
    2, Amster
    3, am

    I want to find the folder that holds the most possible information:
    Research of Amsterdam must return 1; the Amsterdamned search should return 1; the search of America should return 3; the search of the United States should return 0 (or null).

    So the logic is to search for the entire string, and returns the id when it is recognized. If not found remove most characters right and search until you find or has empty string.

    Since this logic must be part of SQL, I wonder if there is a clever (without write a PL/SQL function) way to solve this problem?

    I'm curious.

    Geert.

    See the report below...

    SELECT t2.place_id
    FROM   (SELECT t.*,
                   Decode(( Instr(Lower('&value'), Lower(t.place_name), 1,
                   1) ), 1, Length(t.place_name),
                         0) AS len
            FROM   actual_places t
            ORDER  BY len DESC) t2
    WHERE  t2.len != 0
           AND rownum = 1; 
    

    AmsteRdamX - 1
    Amsterdam - 1
    AmsterX - 2
    Amster - 2
    aMs - 3
    am - 3
    Am --3
    test - NULL

  • How to find the last record of the extracted records

    Dear members,

    I have an OFA Page in which I view record master detail. For each master record can one or more detail records.

    In the page I got the button NEXT. If the user clicks the next button, I'm populating the next record of the master and its corresponding detail records.

    To achieve this, I wrote the code below in AM:_


    Public Sub findNextRec()
    *{*
    String headerID = null;
    Rank rank is getMaster_VO1 () .next ();.
    if(Row!=null)
    *{*

    headerID = row.getAttribute ("HeaderId") m:System.NET.SocketAddress.ToString ();
    getDetail_VO1 (.setMaxFetchSize(-1));
    getDetail_VO1 () .setWhereClause (null);
    getDetail_VO1 () .addWhereClause ("header_id in (: 1)" ");
    getDetail_VO1 () .setWhereClauseParams (null);
    getDetail_VO1 (.setWhereClauseParam(0,headerID));
    getDetail_VO1 () .executeQuery ();

    *}*
    *}*

    My CO code in processFormRequest method is as follows:_


    If (PageContext.GetParameter ("Next")! = null)
    *{*
    am.invokeMethod ("findNextRec");
    *}*

    Here my requirement is that if it's a last drive, I want to show the user a message saying it's last recording. To achieve this please let me know what the code should be written.

    Thanks in advance.

    Best regards
    Arun D. Reddy

    Arun,

    If my interpretation is correct, then you can achieve the same thing by making some minor changes to your existing code.

    public void findNextRec()
    {
    String headerID=null;
    Row row = getMaster_VO1().next();
    if(row!=null) //your code will return null when if there is no record
    {
    headerID=row.getAttribute("HeaderId").toString();
    getDetail_VO1().setMaxFetchSize(-1);
    getDetail_VO1().setWhereClause(null);
    getDetail_VO1().addWhereClause("header_id in (:1)");
    getDetail_VO1().setWhereClauseParams(null);
    getDetail_VO1().setWhereClauseParam(0,headerID);
    getDetail_VO1().executeQuery();
    }
    else{
    //write down the message that there exist no more rows (custom message)
    
         }
    }
    

    Kind regards
    GYAN

  • Query to find the match on two areas where the third does not work...

    Faced with this one...

    Light of the example data
    SECTION     GROUPID     SUBGROUPID     COMPONENT     PNUM     USERNAME
    HVAC     AC     MOTOR          HOSE          111.1     BOB
    HVAC     AC     MOTOR          HOSE          111.2     BOB
    HVAC     AC     MOTOR          HOSE          111.3     JIM
    
    HVAC     AC     MOTOR          BOLT          411     BOB
    HVAC     AC     MOTOR          BOLT          411     BOB
    HVAC     AC     MOTOR          BOLT          411     BOB
    HVAC     AC     MOTOR          BOLT          (null)     (null)
    
    HVAC     AC     MOTOR          CLAMP          211.1     BOB
    HVAC     AC     MOTOR          CLAMP          211.2     JIM
    HVAC     AC     MOTOR          CLAMP          211.3     BOB
    
    HVAC     AC     MOTOR          STRAP          611.1     JIM
    
    HVAC     AC     MOTOR          BELT          811.3     BOB
    HVAC     AC     MOTOR          BELT          (null)     (null)
    
    HVAC     AC     MOTOR          DISC          (null)     (null)
    HVAC     AC     MOTOR          DISC          (null)     (null)
    HVAC     AC     MOTOR          DISC          (null)     (null)
         
    What I need is a list of records where the GroupID and component matching, and where they had a PNUM who were not all the same

    So in this case I would like to only these returned, Section/SubgroupID/username are not required to match on anything whatsoever, but here to view the
    additional data that may be there. Items that have PNUM which IS NULL should be ignored? Example would be the example above where the PNUM
    for a record was 811,3 while one below is null, which should not return. Its considered to be 'ok' and does not need to be reported.

    SECTION     GROUPID     SUBGROUPID     COMPONENT     PNUM     USERNAME
    HVAC     AC     MOTOR          HOSE          111.1     BOB
    HVAC     AC     MOTOR          HOSE          111.2     BOB
    HVAC     AC     MOTOR          HOSE          111.3     JIM
    
    HVAC     AC     MOTOR          CLAMP          211.1     BOB
    HVAC     AC     MOTOR          CLAMP          211.2     JIM
    HVAC     AC     MOTOR          CLAMP          211.3     BOB

    Hello

    To identify all incompatible groupid/component combinations:

    SELECT       groupid, component
    FROM       table_x
    GROUP BY  groupid, component
    HAVING       COUNT (DISTINCT pnum)     > 1
    ;
    

    To view information on all lines with these groupid/component combinations, use the query above in an IN subquery:

    SELECT  *
    FROM     table_x
    WHERE     (groupid, component)  IN
         (
              SELECT       groupid, component
              FROM       table_x
              GROUP BY  groupid, component
              HAVING       COUNT (DISTINCT pnum)     > 1
            )
    ;
    

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • I installed firefox Aurora, but can I uninstall it and go back to Firefox 11 if I find the 11 version better? Will I lose the history and bookmarks?

    I installed the new version 13, called Aurora. I currently have, but if I start to dislike the new features (until now I do! But I have to ask) can I 'come back' to the 'good old' Firefox 11?
    Will I be losing my data and settings? History and bookmarks?

    My computer is a Pentium M 1, 6 GHz (2004) and version 11 seemed very stable. I installed Aurora is because I wanted to try your new software.

    Yes, you can uninstall the aurora and install the latest stable version whenever you want without losing the personal data because your profile data is stored in the Firefox profile folder, so you will not lose your bookmarks or other personal data.

    Thank you

  • find the parenthesis

    Is there a shortcut in the IDE source code key to move the cursor to the corresponding opening or the closing parenthesis? Can't seem to find a way to do it. If I move the cursor over a "{" for example, I want to find the matching '} '. Is there a way to do this?

    B

  • Find the location of a particular line

    Hello

    Is is possible to find the location of a particular row of a table in a database?

    For example: I need to find in which tablespace or datafile is the particular row of a table.

    Kind regards

    007

    007 wrote:
    Hi 909592,

    How to find the IDENTIFIER records in a table?

    Kind regards

    007

    Each line/record has a rowid that are associated with.

    SQL> select rowid, DEPTNO, DNAME, LOC from dept;
    
    ROWID                  DEPTNO DNAME          LOC
    ------------------ ---------- -------------- -------------
    AAAR3qAAEAAAACHAAA         10 ACCOUNTING     NEW YORK
    AAAR3qAAEAAAACHAAB         20 RESEARCH       DALLAS
    AAAR3qAAEAAAACHAAC         30 SALES          CHICAGO
    AAAR3qAAEAAAACHAAD         40 OPERATIONS     BOSTON
    

    As above, you have rowid for each line in the dept table. You must get the rowid in listing files

  • activation and deactivation of the button in the block record multi

    Hi all
    I use
    Forms [32 bit] Version 6.0.8.24.1 (Production)
    Oracle Database 10g Release 10.2.0.1.0 - Production
    I have a multi record block each block contains a button (the button is to approve the record in terms of change of status)
    I have elements such as the date, remarks and button
    the button should be enabled if the remarks is not null in the case otherwise it should be disabled.
    I wrote to this effect in the pre-record trigger
    if :record is null then
       set_item_property('button',enabled,property_false);
    else
          set_item_property('button',enabled,property_false);
    end if;
    What problem is enable and disable has repercussions on all the buttons in the block. in other words, if the remarks of the first record is null then all records button is disabled. If the observations of the first record column is not null, then all the records in the column of buttons is enabled.
    I have to enable and disable the button for the corresponding record.that ways if the remarks of the first record column is not null not so only records first button should be activated and others should be disabled.

    Thank you...

    Hello

    but I'm not able to do.

    You can find the current record Y_POS 
    

    This means that whatever the user record navigates according to whether the button position gets her past set.but not.
    for example the user navigates up to the fourth record that will settle the position of the button but if user navigates back to the first record. the position of the button is going to the fifth record?

    V_ITEM_Y_POS: = GET_ITEM_PROPERTY ("NOM_ELEMENT", Y_POS);

    Please note that do not use the button element to get the Y_POS.
    This should be another element in the block, then button as a buttons position will continue to change on
    What you are to get the Y_POS of button which is the fourth position of the record for the first time so, it is fair,
    second time you set Y_POS button which is 4th record + first recording which is the fifth album,.
    you need to find is the Y_POS from a fixed point in the block.

    in your description what do you mean by top_record. Why I ask, is because it is multi record block(showing_10_records).so will appear every 10. no record may be hiding.

    Top of page record is the first record in the block.
    For example, in a record 10 block, if there are 20 records then if you navigate the records, if you go to the 11th, 12th, 13th, 14th... the other then your TOP_RECORD be record No 2, 3, 4,... is the first record that is displayed in the block that is not always 1, and will be 1 only for the first 10 rcords.
    If we use: system.cursor_record we will not be able to get the Y_POS exact numbers of superior record then 10 which will put the button located under the last (10th) record, which is not what we want, so need to find the TOP_RECORD.

    Best regards

    Arif Khadas

  • I can't find the recorded files recently in my document folder

    I can't find the recorded files recently in my document folder

    Maybe not save them there.

    Assuming that you have saved the today, go to the Finder, type 'Today' in the oval at top right.

  • During the installation of Firefox 4 beta, he told me that it does not work on my Mac. When I go to system requirements, need a page for Firefox3.6 requirements. Where can I find the requirements for the beta?

    The link to the minimum configuration for Firefox 4 beta takes you to a page that gives you the requirements for Firefox 3.6 instead. I guess that the requirements for the beta are different, that I can't seem to install the beta on my Mac. Where can I find the beta version of system requirements?

    Firefox 4 will not work on the Mac PPC, for Mac it needs the Intel processor. There is an accumulation of third parties based on Firefox 4 beta, which should work on Mac PPC, for details, see http://www.floodgap.com/software/tenfourfox/

Maybe you are looking for