<?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>Question Re: FOR READ ONLY on subquery in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/for-read-only-on-subquery/qaa-p/13847330#M4878173</link>
    <description>&lt;P&gt;Short answer: Subqueries can't be anything other than read-only, so FOR READ ONLY is superfluous.&lt;/P&gt;
&lt;P&gt;The FOR READ ONLY clause is only allowed in an outer SELECT statement, not a subquery, because only a SELECT statement can be used to fetch and update rows in a cursor... in other words, FOR UPDATE and hence FOR READ ONLY make no sense on a subquery... so you'll get the same SQLCODE -131 if you run your query on a SQL Anywhere server.&lt;/P&gt;
&lt;P&gt;Here are a couple of examples...&lt;/P&gt;
&lt;PRE&gt;Could not execute statement.
Syntax error near 'READ' on line 5
SQLCODE=-131, ODBC 3 State="42000"
Line 1, column 1

SELECT *
  FROM dummy
 WHERE dummy_col IN ( SELECT dummy_col
                        FROM dummy
                      FOR READ ONLY )

-----

Could not execute statement.
Syntax error near 'UPDATE' on line 5
SQLCODE=-131, ODBC 3 State="42000"
Line 1, column 1

SELECT *
  FROM dummy
 WHERE dummy_col IN ( SELECT dummy_col
                        FROM dummy
                      FOR UPDATE )

&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Mar 2013 10:10:41 GMT</pubDate>
    <dc:creator>Breck_Carter</dc:creator>
    <dc:date>2013-03-12T10:10:41Z</dc:date>
    <item>
      <title>FOR READ ONLY on subquery</title>
      <link>https://community.sap.com/t5/technology-q-a/for-read-only-on-subquery/qaq-p/13847329</link>
      <description>&lt;P&gt;I try to found some information about limitations of used a SELECT using FOR READ ONLY on subqueries (Ultralite), everytime i try this an error occurs:&lt;/P&gt;
&lt;P&gt;Syntax error near 'FOR' [SQL Offset: 1735] 
SQLCODE=-131, ODB 3 STATE="4200" &lt;/P&gt;
&lt;P&gt;Select example:&lt;/P&gt;
&lt;P&gt;SELECT COUNT(*) as groupCount FROM (SELECT name
    FROM table
FOR READ ONLY
) AS DS (name)&lt;/P&gt;
&lt;P&gt;This really don't work? why?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2013 09:41:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/for-read-only-on-subquery/qaq-p/13847329</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-03-12T09:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: FOR READ ONLY on subquery</title>
      <link>https://community.sap.com/t5/technology-q-a/for-read-only-on-subquery/qaa-p/13847330#M4878173</link>
      <description>&lt;P&gt;Short answer: Subqueries can't be anything other than read-only, so FOR READ ONLY is superfluous.&lt;/P&gt;
&lt;P&gt;The FOR READ ONLY clause is only allowed in an outer SELECT statement, not a subquery, because only a SELECT statement can be used to fetch and update rows in a cursor... in other words, FOR UPDATE and hence FOR READ ONLY make no sense on a subquery... so you'll get the same SQLCODE -131 if you run your query on a SQL Anywhere server.&lt;/P&gt;
&lt;P&gt;Here are a couple of examples...&lt;/P&gt;
&lt;PRE&gt;Could not execute statement.
Syntax error near 'READ' on line 5
SQLCODE=-131, ODBC 3 State="42000"
Line 1, column 1

SELECT *
  FROM dummy
 WHERE dummy_col IN ( SELECT dummy_col
                        FROM dummy
                      FOR READ ONLY )

-----

Could not execute statement.
Syntax error near 'UPDATE' on line 5
SQLCODE=-131, ODBC 3 State="42000"
Line 1, column 1

SELECT *
  FROM dummy
 WHERE dummy_col IN ( SELECT dummy_col
                        FROM dummy
                      FOR UPDATE )

&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Mar 2013 10:10:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/for-read-only-on-subquery/qaa-p/13847330#M4878173</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2013-03-12T10:10:41Z</dc:date>
    </item>
  </channel>
</rss>

