Find first record starting with most extensive ability

Hi,
This question might have been asked before but I don't know how to describe it in the search field.
There are 3 records with 2 fields (id, name). These records are:
1,Amsterdam
2,Amster
3,Am
I want to find the record that holds the most possible information:
searching Amsterdam must return 1; searching Amsterdamned must return 1; searching America must return 3; searching United must return 0 (or null).
So the logic is to search for the whole string and return the id when found. If not found remove the most right character and search until found or a empty string.
Since this logic has to be a part of SQL I wonder if there is a smart way (without writing a PL/SQL function) to solve this?
I'm curious.
Geert.

Hi, Geert,
So you're only interested in strings that start the same way? That is, the fact that 'Amsterdam' and 'United' have the substring 'te' in common doesn't matter, because 'te' comes in the middle of those strings.
If that's so, you can use LIKE to compare the strings.
WITH   got_r_num    AS
     SELECT     p.place_name
     ,     a.place_id
     ,     a.place_name     AS a_place_name          -- Not needed, nut may be nice
     ,     RANK () OVER ( PARTITION BY  p.place_name
                           ORDER BY          LENGTH (a.place_name)  DESC
                    )  AS r_num
     FROM          possible_places  p
     LEFT OUTER JOIN      actual_places       a  ON  p.place_name LIKE a.place_name || '%'
SELECT       place_name
,       NVL (place_id, 0)     AS place_id     -- or, if you want NULL, just place_id
,       a_place_name                       -- if wanted
FROM       got_r_num
WHERE       r_num     = 1
ORDER BY  place_name
;Whenever you have a problem, please post CREATE TABLE and INSERT statments for some sample data, like this:
CREATE TABLE     actual_places
(   place_id     NUMBER (6)     PRIMARY KEY
,   place_name     VARCHAR2 (20)     
INSERT INTO actual_places (place_id, place_name) VALUES (1,  'Amsterdam');
INSERT INTO actual_places (place_id, place_name) VALUES (2,  'Amster');
INSERT INTO actual_places (place_id, place_name) VALUES (3,  'Am');
CREATE TABLE     possible_places
(   place_name     VARCHAR2 (20)     PRIMARY KEY
INSERT INTO possible_places (place_name) VALUES ('Amsterdam');
INSERT INTO possible_places (place_name) VALUES ('Amsterdamned');
INSERT INTO possible_places (place_name) VALUES ('America');
INSERT INTO possible_places (place_name) VALUES ('United');Also, post the results you want from that data, exactly as you want to see them. The query above produces this output:
PLACE_NAME             PLACE_ID A_PLACE_NAME
America                       3 Am
Amsterdam                     1 Amsterdam
Amsterdamned                  1 Amsterdam
United                        0See the forum FAQ {message:id=9360002}

Similar Messages

  • There are several items I'd like to remove that are on the line at the top of my page that starts with "Most Visited," and I have been unable to find a way to remove them.

    At the top of the page, between the address of the page I'm on and the tabs that are open is a line that starts with "Most Visited" and also includes Amazon, aBay, Yahoo, etc., all of which I want to keep. But there are also a number of other links that I don't want but can't find a way to delete. I've looked at suggestions til my eyes bugged out of my head, but nothing I've found allows me to get rid of them. Only one of them is something I saved, but it is no longer usable.

    The mouse that came with my Mac does not have a right click feature. When I try to highlight and click, it just opens the link I don't want anymore. What I want to do is remove unwanted links from the top bar. For example, I no longer use GoodSearch or myEarthLink, but I can't delete them. There are also some links that never should have found their way up there, and I don't know how they ended up there, and I can't remove them either. I've read through a ton of questions and answers, and I can't find one that addresses the problem. With my Safari browser, all I have to do to remove an unwanted link is to click and drag it to the trash. It doesn't appear to work that way with Firefox, to my chagrin. I hope this better explains my question. Maybe that will give you a better insight into a solution.

  • Find first record in a set of record

    I want to find first record in a set of record .What built in function shall i use and which trigger should I use.Please help.

    Hi,
    First_record takes you to the position of that first record, but doesn't gives you the value of the record, you have to get it form the :block_name.item_name
    Jose.

  • Could not find the record specified with data_record option

    Hi, we've got the same error in a couple of templates, but have no idea what can be the cause or solution. Does anyone know where I should look when I got "Could not find the record specified with data_record option" as message?
    Thanks in advance!

    Hi Raf,
    That is what it normally is.  I thought it might be related to a multi-record form, like in this blog http://blogs.adobe.com/formfeed/2009/09/working_with_multiple_data_rec.html.
    That blog does not really go into it, but if your "record" is not the directly under the <xfa:data> element then you need a <record> element under config/data to say what the node is, something like <record>Worker</record>.
    You error message sounded familiar but I have not been able to reproduce it, but then I've moved on a couple of versions of Designer.
    Is it possible for you to share your form and seed data?
    Regards
    Bruce

  • How to i replace the firefox toolbar....and remove the toolbar that starts with MOST VISITED and SUGGESTED SITES

    Somehow lost the toolbar that has the page return arrows and refresh and stop icons. How can I replace those and remove a toolbar that starts with MOST VISITED and lists several SUGGESTED SITES.

    hello kittyheckel, please see [[Navigation buttons like back, home, bookmarks and reload are missing]]. you'll want to disable the bookmarks toolbar & enable the navigation toolbar.

  • ABAP code to find records starting with Z or Y

    Hi,
    I am trying to find the records in a SAP table, where all the values for a particular field start with Z and Y. What is the coding statement for this?
    I tried this but it does not seem to be correct.
    SELECT field
        FROM table
        INTO TABLE t_itab
        WHERE field LIKE 'z*'.
    Can someone correct me or suggest me the best solution for this? Thanks.
    Moderator message - Unfortunarely, this is not a training forum. You can get a lot of information using F1 - thread locked
    Edited by: Rob Burbank on Nov 24, 2009 4:25 PM

    If you have to do in urself
    DATA: i_reptx TYPE STANDARD TABLE OF textpool WITH HEADER LINE.
    READ TEXTPOOL 'ZJ_ALV' INTO i_reptx.
    and describe the itab.. and get  the lines.
    In conjunction with TADIR table to get the program repository.

  • Getting started with iAd extension

    Hi,
    I recently purchased the iAd extension for ios package from milkman and am having trouble implementing it.
    I have followed the Getting Started document but am having no joy. I have attached some screenshots to show how it is set up and the problems.
    1) API library included
    2) Code used in first frame of test app file
    3) Errors received when publishing
    4) Errors received when private is taken out
    5) When I turn strict mode off and publish, I just get a blank white screen when viewing the app on my iPhone.
    Please help!
    Thanks!

    Your problem is right there in the errors. Looks like you are coding on the time line instead of the class. That's fine, but that means get rid of class related things like private function and extends class stuff. That is what your first error is about. When you do that you are getting the second error, here I can see in your code you have set up the listeners for those 2 functions but you do not have the actual function onBannerAdLoaded and onBannerAdFailed. Find those two in the docs or below add them to your code.
    function onBannerAdLoaded(e:IAdEvent):void
            trace("banner ad loaded.");
    private function onBannerAdFailed(e:IAdErrorEvent):void
            trace("banner ad failed");
    The last error is a typo on your part. In line 18 you have a lowercase ad as in Iad it should be IAd, remember flash is very case sensitive. So change it to this.
    IAd.iAd.createBannerAd(IAdBannerAlignment.TOP,IAdContentSize.PORTRAIT_AND_LANDSCAPE);

  • Learn Java first or start with C?

    I am completely new to the programming world. However, I'm an MCP with WinNT experience and have worked in the computer industry (desktop, hardware and various software support) for almost four years.
    I want to know if it's actually all right to start learning how to program with Java 2 without any previous programming experience. Plus, would Java 2 be a good place to start? I've taken a fast-paced 5-day crash course at a local State university and actually seemed to understand the concepts and was able to answer the instructors' questions. (What was surprising, and somewhat scary, was that I was able to answer questions that the regular C programmers couldn't seem to answer).
    However, I just want to make sure I'm following the right path.
    Please advise if you can.
    Thanks!
    -MB

    This is the main reason I'd pick Java to teach a newbie about programming:
    It pretty much lets you do anything you can do with C and C++ (short of directly manipulating computer memory) with a syntax that's much simpler and elegant. Java just gives you fewer things to worry about, and yet tests all the important skills a programmer needs.
    But it's still possible to write bad Java code. Java has it's own share of bad programming habits.
    Grab a good Java book. My favorite is Java in a Nutshell by David Flanagan. It's concise and to the point, which may or may not be the best for someone totally new to programming. Download the Java Development Kit (it's free). And get your hands dirty. Start out with a simple tic-tac-toe program, and go from there. That's the only way to find out if programming is hard or not.
    And add the Java Developer Connection to your Internet bookmarks list. It's an invaluable resource for all programmers, new and experienced.
    If you have any other questions I'd be more than happy to help.
    Juan
    [email protected]

  • Write to Text File.vi Output file all but first line start with tab

    The attached PNG shows the code used to build up concatenated strings into a string array for the first four lines, thence to a string Array, to Spreadsheet String.vi and, finally, the use of Write to Text File.vi
    The lower right corner shows the result loaded into a spreadsheet. Note the 3 blank entries marked by a filled red rectangle. Examination of hidden characters shows there is a tab at the beginning of lines 2, 3 and 4.
    There is no tab shown in the code. How do those tabs get there? How do I stop them?
    I have tried with the option "Convert EOL" both on and off with no difference.
    The Help states that an OS-dependent EOL character is appended to each line. I can't imagine the Windows EOL character includes a tab.
    Solved!
    Go to Solution.
    Attachments:
    Tab Mystery.PNG ‏29 KB

    wildcatherder wrote:
    I am still puzzled as to why those additional tabs were added by Array to Spreadsheet String.  I'm holding in my hand a printout of an old LabVIEW 8 program with that construction, which is known to work properly.
    Makes complete sense when you look at your code.  You build a string, including an end-of-line character, and put that string into an array.  Then, when you run it through Array to Spreadsheet String, it puts a tab after every array element, and new line at the end of each row in the array.  The first element of your array contains a new line but Array to Spreadsheet String doesn't know about it; it still inserts a tab between that array element and the next one, giving you the tabs.

  • Find first 3 letters with Form search?

    Greetings
    I have a search form in which the user types the first 3
    letters of a word - the results should display only those words
    that begin with the letters.
    What would the correct SQL format be to accomplish this?
    WHERE myword LIKE '%#Trim(FORM.Keyword)#%' ?
    Thanks in advance.

    Thanks again for your quick response, Dan.
    Here is the error message I am getting (MS Access DB):
    Error Executing Database Query.
    Missing ), ], or Item in query expression
    'upper(substr(vendor_company,1, 3) = ?'.

  • Report's First Page Start with a specified page number.

    I want that my first page of the report should start by a number whixh i want. Say the PageNo on the first page is 32 and it will proceed as 33, 34, 35 ....so on.
    What to do?

    hello,
    you can modify the starting value for the page number by using the "Page Numbering" property of your page number field. there you can define where you want your page numbers to start.
    regards,
    ph.

  • How do I make Bridge start with most recent folder and photos?

    Bridge always opens with a folder I was working with last March--How can I get bridge to open at the folder and photos I was working with when I last closed down the program?

    You could try the Bridge Forum.
    http://forums.adobe.com/community/bridge/general
    Apart from that have trashed prefs and repaired permissions yet?

  • Spotlight content search : excludes files with .php5 extension

    My Spotlight does not find strings in files with .php5 extension. It probably does not consider these as text files.
    How can I change that ?

    I guess I found the right page :
    http://developer.apple.com/documentation/Carbon/Conceptual/understandingutis/understand_utis_intro/chapter_1_section_1.html#//appleref/doc/uid/TP40001319-CH201-SW1

  • URL of BCS search results start with bdc3://

    Hello,
    I am using sharepoint BDC in Sharepoint 2013. I have created profile page and given permissions. I configured search. I have full crawled 2-3 times and incremental crawl. I found total records crawled are more than total record in sql database.
    When I checked I found 2 records start with "bdc3://".
    Please let me know how to prevent crawling the url starting with bdc3://.
    Thanks,
    Lovkesh Patel

    Hi Lovkesh,
    According to your description, my understanding is that you do not want to crawl the contents start with bdc3:// in SharePoint 2013.
    I recommend to create Crawl Rules with bdc3://* as the path to exclude the content start with bdc3:// from crawling in Search Service Application to see if the issue still occurs.
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Caution: n00b question: What is an object starting with X

    Please don't say a xylophone.
    I mean if I have table z1234 and I see an error in a short dump where the object involved called xz1234, where did the object come from?
    Kind regards,
    Peter

    Hi Peter,
    Actually you are not very clear. You mentioned table Z1234 (Is this present in SE11 ?). You mentioned table xz1234. In fact i cannot find any table starting with X in my system. Are you sure xz1234 is a database table.
    xz1234 should be some internal table declaration or work area for table Z1234.
    DATA : xz1234 TYPE TABLE OF z1234.
    or
    DATA : xz1234 TYPE z1234.
    As Thomas said we are gussing here. Need more information.
    Regards

Maybe you are looking for

  • Degraded print in pdf files

    When I save an article from the internet as a pdf file, the print on my saved file is degraded. The letters do not look solid. This makes the text difficult to read. This does not happen with files that I scan into a pdf file. The print looks the sam

  • Can't Scan after new installation

    A bit of background; Dell laptop Windows 8.1 64bit HP Officejet 6500 e709n I finally managed to install the full set of printer drivers (HP Solution Center) on this new laptop ....which btw took hours of research,  just to learn that I can't scan.  I

  • ERP2005 SR3 Create SAP Stored Procedures Error

    Hi Seniors, I have tried to install SAP ERP ECC 6.0 IDES ERP2005 SR3 , I got the error in installation step 19/26 (Create SAP Stored Procedures). OS : WIN 2008 SERVER DB : MS SQL 2008 I have fallow the Note 1152240. Error log : ERROR 2010-03-02 12:08

  • Linking multiple documents in solar01

    Hi Guys, Linking multiple documents in SolMan is a pain, and I am trying to find out if anyone of you have a way that allows linking multiple documents in SolMan at a go. We need to do a 3 way match between document types - Say Doc A, Doc B and Doc C

  • Can I get a discounted Creative Suite 6 Design & Web Premium for Mac if I already own the Windows ve

    I have a desktop computer with the Windows version of Creative Suite 6 Design & Web Premium. I have a Mac laptop and would like to run the suite from it too. Is there a way to get a discounted suite for this second computer?