<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic SELECT SINGLE weird behaviour in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406056#M1547402</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have written the following query to pick up the address no. In case, there are multiple entries found in table ADRC according to my WHERE clause condition, the query returns the &lt;STRONG&gt;first&lt;/STRONG&gt; address no out of those multiple address nos in one system 'A' whereas it returns the &lt;STRONG&gt;last&lt;/STRONG&gt; address no. in similar situation in a different  system B.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT SINGLE addrnumber&lt;/P&gt;&lt;P&gt;                name1&lt;/P&gt;&lt;P&gt;                sort1&lt;/P&gt;&lt;P&gt;                street&lt;/P&gt;&lt;P&gt;                house_num1&lt;/P&gt;&lt;P&gt;                city1&lt;/P&gt;&lt;P&gt;                region&lt;/P&gt;&lt;P&gt;                post_code1&lt;/P&gt;&lt;P&gt;                INTO wa_customers&lt;/P&gt;&lt;P&gt;                FROM adrc&lt;/P&gt;&lt;P&gt;                WHERE sort2       EQ 'ABC'&lt;/P&gt;&lt;P&gt;                AND addr_group EQ 'XY'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea why the same query is behaving differently in two system?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 Oct 2010 23:14:47 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-10-27T23:14:47Z</dc:date>
    <item>
      <title>SELECT SINGLE weird behaviour</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406056#M1547402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have written the following query to pick up the address no. In case, there are multiple entries found in table ADRC according to my WHERE clause condition, the query returns the &lt;STRONG&gt;first&lt;/STRONG&gt; address no out of those multiple address nos in one system 'A' whereas it returns the &lt;STRONG&gt;last&lt;/STRONG&gt; address no. in similar situation in a different  system B.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT SINGLE addrnumber&lt;/P&gt;&lt;P&gt;                name1&lt;/P&gt;&lt;P&gt;                sort1&lt;/P&gt;&lt;P&gt;                street&lt;/P&gt;&lt;P&gt;                house_num1&lt;/P&gt;&lt;P&gt;                city1&lt;/P&gt;&lt;P&gt;                region&lt;/P&gt;&lt;P&gt;                post_code1&lt;/P&gt;&lt;P&gt;                INTO wa_customers&lt;/P&gt;&lt;P&gt;                FROM adrc&lt;/P&gt;&lt;P&gt;                WHERE sort2       EQ 'ABC'&lt;/P&gt;&lt;P&gt;                AND addr_group EQ 'XY'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea why the same query is behaving differently in two system?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Oct 2010 23:14:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406056#M1547402</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-27T23:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT SINGLE weird behaviour</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406057#M1547403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT SINGLE returns first record which corresponds to defined conditions. So my guess is that your issue is caused by secondary index. There is a secondary index for SORT2 and I assume it is used for your query. This index is different on your systems and therefore you get different first record when it's used. If you want to get always the first one then you need to use SORT and UP TO 1 ROWS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Oct 2010 00:34:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406057#M1547403</guid>
      <dc:creator>mvoros</dc:creator>
      <dc:date>2010-10-28T00:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT SINGLE weird behaviour</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406058#M1547404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This behaviour is not weird. SELECT SINGLE is supposed to be used with full primary (and maybe unique secondary) keys, providing all key fields with an EQ condition. If you use SELECT SINGLE for other type of access, your result can be random, e.g. the first record &lt;EM&gt;in order as they were entered into the database&lt;/EM&gt; will be found.&lt;/P&gt;&lt;P&gt;Use clean programming to get clean results.&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Oct 2010 08:43:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406058#M1547404</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2010-10-28T08:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT SINGLE weird behaviour</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406059#M1547405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thomas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your suggestion !! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In our business, this particular WHERE condition always result in unique entry only. In one of the system, there was a data issue and we had multiple entries found with this selection.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We cannot use primary keys of ADRC table in our case. I was wondering, if this is a 'random behaviour' of SELECT SINGLE, or there is some rule which governs which record to pick up in case multiple records found accidently.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I could see, it is either picking first record or the last record in case there are multiple entries found. Is there any rule behind it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rudresh&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rudresh Chand on Oct 28, 2010 3:49 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Oct 2010 13:48:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406059#M1547405</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-28T13:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT SINGLE weird behaviour</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406060#M1547406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This might be database dependent, but you can try if SELECT * UP TO 1 ROWS in combination with ORDER BY sort2 will always give the desired result (slightly extending Martin's recommendation).&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Oct 2010 14:30:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406060#M1547406</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2010-10-28T14:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT SINGLE weird behaviour</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406061#M1547407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There probably is, but...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In any case, you can &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT ... UP TO 1 ROWS ORDER BY whatever...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Oct 2010 14:30:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406061#M1547407</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-28T14:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT SINGLE weird behaviour</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406062#M1547408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Select single needs a complete key irrepsective how the data is in table.tomake it refer to primary index you select single.Foryour case use Select uptoone rows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nabheet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Oct 2010 05:36:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406062#M1547408</guid>
      <dc:creator>nabheetscn</dc:creator>
      <dc:date>2010-10-29T05:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT SINGLE weird behaviour</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406063#M1547409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;as we should have learned in RDBMS and SQL basic classes ;o) the order of rows returned by a select statement is not defined as long as there is no ORDER BY definition in the statement. As SELECT SINGLE internally gets all records and then takes the first record of the result set, it is not defined which record is returned. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So even if you run a statement on the same system several times the returned record can be fully random. That it is not always completely random is more a random technical effect of the algorithms and access strategies the data base implements within the frame defined by the DB/SQL standards. So nothing is garanteed the next DB patch could change the behavouir completely if the data base implements a new algorithm. So do not trust in such not defined, not documented and not garanteed system behaviour.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From the implementation aspect I'd personally prefer a SELECT * INTO TABLE followed by a READ TABLE INDEX 1. The select single w/o full primary key and with ORDER BY bypasses the table buffers and should be slower. If the statement should always return one line there is no need for sorting the table. If there should be one line and two are returned the data is inconsistent, sorting for a certain record won't make this any better. Here I would add an assertion that only one record was found so the application stops if data is corrupt and someone takes care of correcting the data. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Roman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Oct 2010 15:28:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406063#M1547409</guid>
      <dc:creator>romanweise</dc:creator>
      <dc:date>2010-10-30T15:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT SINGLE weird behaviour</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406064#M1547410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Roman,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your explanation !!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, I observed the SELECT SINGLE behaviour over some time and found that most of the time it is picking up the first or the last entry.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For my case, I am reading multiple records and SORTing them in DESCENDING and READING ..INDEX 1 as I have to pick up the latest address number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT..UP TO n rows...ORDER BY gives very low performance and is not advisable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rudresh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Nov 2010 02:51:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-single-weird-behaviour/m-p/7406064#M1547410</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-11-01T02:51:15Z</dc:date>
    </item>
  </channel>
</rss>

