<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Queries on BareSQL.com</title>
    <link>https://baresql.com/tags/queries/</link>
    <description>Recent content in Queries on BareSQL.com</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 26 Oct 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://baresql.com/tags/queries/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Columns Missing From GROUP BY Work on SQLite and MariaDB and Fail on PostgreSQL and MySQL</title>
      <link>https://baresql.com/columns-missing-from-group-by-work-on-sqlite-and-mariadb-and-fail-on-postgresql-and-mysql/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/columns-missing-from-group-by-work-on-sqlite-and-mariadb-and-fail-on-postgresql-and-mysql/</guid>
      <description>&lt;p&gt;&lt;code&gt;SELECT customer_id, name, SUM(total) FROM orders GROUP BY customer_id&lt;/code&gt; is the kind of query that runs for years on SQLite or MariaDB. Point the same code at PostgreSQL or MySQL and it stops with an error, because name is neither grouped nor summed.&lt;/p&gt;&#xA;&lt;p&gt;SELECT a, b FROM t GROUP BY a asks for one b per group without saying which. SQLite and MariaDB pick one (MariaDB’s default mode leaves out ONLY_FULL_GROUP_BY). PostgreSQL and MySQL stop with an error, unless the grouped column is the table’s primary key, which fixes every other column of that table.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Comparing a Boolean With 1 Works on MySQL and SQLite and Fails on PostgreSQL</title>
      <link>https://baresql.com/comparing-a-boolean-with-1-works-on-mysql-and-sqlite-and-fails-on-postgresql/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/comparing-a-boolean-with-1-works-on-mysql-and-sqlite-and-fails-on-postgresql/</guid>
      <description>&lt;p&gt;&lt;code&gt;WHERE active = 1&lt;/code&gt; is the usual way to test a flag on MySQL, and SQLite and MariaDB read it the same way. Moved to PostgreSQL, the query stops with an error.&lt;/p&gt;&#xA;&lt;p&gt;On SQLite, MySQL and MariaDB a boolean is the number 0 or 1, and TRUE is another way to write 1. PostgreSQL has a real boolean type with no automatic conversion from integers, so code written for MySQL that compares flags with 1 stops there.&lt;/p&gt;</description>
    </item>
    <item>
      <title>COUNT DISTINCT With Two Columns Works on MySQL and Fails on PostgreSQL and SQLite</title>
      <link>https://baresql.com/count-distinct-with-two-columns-works-on-mysql-and-fails-on-postgresql-and-sqlite/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/count-distinct-with-two-columns-works-on-mysql-and-fails-on-postgresql-and-sqlite/</guid>
      <description>&lt;p&gt;&lt;code&gt;COUNT(DISTINCT customer_id, product_id)&lt;/code&gt; counts the distinct pairs on MySQL and MariaDB. SQLite and PostgreSQL take a single expression in &lt;code&gt;COUNT(DISTINCT ...)&lt;/code&gt; and refuse it.&lt;/p&gt;&#xA;&lt;p&gt;SQLite reports the wrong number of arguments and PostgreSQL a missing function.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://baresql.com/images/rule-count-distinct-columns.png&#34; alt=&#34;SELECT COUNT(DISTINCT a, b) FROM t, run on four engines: SQLite 3.45.1 error: wrong number of arguments to function COUNT(); PostgreSQL 16.15 error: function count(integer, integer) does not exist; MySQL 8.0.46 2; MariaDB 10.11.14 2.&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>DISTINCT ON Works on PostgreSQL Only</title>
      <link>https://baresql.com/distinct-on-works-on-postgresql-only/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/distinct-on-works-on-postgresql-only/</guid>
      <description>&lt;p&gt;&lt;code&gt;DISTINCT ON (customer_id)&lt;/code&gt; is a neat way to keep each customer’s latest order on PostgreSQL, and none of the other three engines has it.&lt;/p&gt;&#xA;&lt;p&gt;SQLite, MySQL and MariaDB report a syntax error. Window functions say the same thing on all four (SQLite 3.25, MySQL 8.0 and MariaDB 10.2 and later).&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://baresql.com/images/rule-distinct-on.png&#34; alt=&#34;SELECT DISTINCT ON (a) a, b FROM t ORDER BY a, b, run on four engines: SQLite 3.45.1 error: near &amp;quot;ON&amp;quot;: syntax error; PostgreSQL 16.15 1, 3; 2, 4; MySQL 8.0.46 error: You have an error in your SQL syntax ... near &#39;ON (a) a, b FROM t ORDER BY a, b&#39; at line 1; MariaDB 10.11.14 error: You have an error in your SQL syntax ... near &#39;ON (a) a, b FROM t ORDER BY a, b&#39; at line 1.&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>FETCH FIRST ROWS ONLY Works on PostgreSQL and MariaDB and Fails on MySQL and SQLite</title>
      <link>https://baresql.com/fetch-first-rows-only-works-on-postgresql-and-mariadb-and-fails-on-mysql-and-sqlite/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/fetch-first-rows-only-works-on-postgresql-and-mariadb-and-fails-on-mysql-and-sqlite/</guid>
      <description>&lt;p&gt;&lt;code&gt;FETCH FIRST 10 ROWS ONLY&lt;/code&gt; is the standard way to ask for the top ten, and PostgreSQL and MariaDB accept it. SQLite and MySQL refuse the query.&lt;/p&gt;&#xA;&lt;p&gt;MariaDB added FETCH FIRST in version 10.6. SQLite and MySQL know only LIMIT, and they refuse OFFSET n ROWS for the same reason.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://baresql.com/images/rule-fetch-first.png&#34; alt=&#34;SELECT x FROM t ORDER BY x FETCH FIRST 2 ROWS ONLY, run on four engines: SQLite 3.45.1 error: near &amp;quot;FETCH&amp;quot;: syntax error; PostgreSQL 16.15 1; 2; MySQL 8.0.46 error: You have an error in your SQL syntax ... near &#39;FETCH FIRST 2 ROWS ONLY&#39; at line 1; MariaDB 10.11.14 1; 2.&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>FULL OUTER JOIN Works on PostgreSQL and SQLite and Fails on MySQL and MariaDB</title>
      <link>https://baresql.com/full-outer-join-works-on-postgresql-and-sqlite-and-fails-on-mysql-and-mariadb/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/full-outer-join-works-on-postgresql-and-sqlite-and-fails-on-mysql-and-mariadb/</guid>
      <description>&lt;p&gt;Matching two lists, such as invoices and payments, to see what is missing on either side calls for a FULL OUTER JOIN. PostgreSQL and SQLite run it, and MySQL and MariaDB refuse it.&lt;/p&gt;&#xA;&lt;p&gt;MySQL and MariaDB have LEFT and RIGHT joins only. SQLite added RIGHT and FULL joins in version 3.39.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://baresql.com/images/rule-full-outer-join.png&#34; alt=&#34;SELECT a.x, b.x FROM a FULL OUTER JOIN b ON a.x = b.x, run on four engines: SQLite 3.45.1 1, NULL; 2, 2; NULL, 3; PostgreSQL 16.15 1, NULL; 2, 2; NULL, 3; MySQL 8.0.46 error: You have an error in your SQL syntax ... near &#39;OUTER JOIN b ON a.x = b.x&#39; at line 1; MariaDB 10.11.14 error: You have an error in your SQL syntax ... near &#39;OUTER JOIN b ON a.x = b.x&#39; at line 1.&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>LIMIT With a Comma Works on MySQL and SQLite and Fails on PostgreSQL</title>
      <link>https://baresql.com/limit-with-a-comma-works-on-mysql-and-sqlite-and-fails-on-postgresql/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/limit-with-a-comma-works-on-mysql-and-sqlite-and-fails-on-postgresql/</guid>
      <description>&lt;p&gt;Paging code written for MySQL often says &lt;code&gt;LIMIT 20, 10&lt;/code&gt;: skip 20 rows, return 10. SQLite and MariaDB read it the same way. PostgreSQL refuses it.&lt;/p&gt;&#xA;&lt;p&gt;In LIMIT a, b the first number is the offset and the second the count, the reverse of the order in which LIMIT ... OFFSET reads.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://baresql.com/images/rule-limit-comma.png&#34; alt=&#34;SELECT x FROM t ORDER BY x LIMIT 1, 2, run on four engines: SQLite 3.45.1 2; 3; PostgreSQL 16.15 error: LIMIT #,# syntax is not supported; MySQL 8.0.46 2; 3; MariaDB 10.11.14 2; 3.&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>MySQL and MariaDB Refuse LIMIT Inside an IN Subquery</title>
      <link>https://baresql.com/mysql-and-mariadb-refuse-limit-inside-an-in-subquery/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/mysql-and-mariadb-refuse-limit-inside-an-in-subquery/</guid>
      <description>&lt;p&gt;Finding the customers behind the ten latest orders with &lt;code&gt;WHERE id IN (SELECT customer_id FROM orders ORDER BY created_at DESC LIMIT 10)&lt;/code&gt; works on SQLite and PostgreSQL. MySQL and MariaDB refuse it.&lt;/p&gt;&#xA;&lt;p&gt;Both report that this version doesn’t yet support &#39;LIMIT &amp;amp; IN/ALL/ANY/SOME subquery&#39;. LIMIT is fine in a subquery used as a table and in one that returns a single value.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://baresql.com/images/rule-limit-in-subquery.png&#34; alt=&#34;SELECT x FROM t WHERE x IN (SELECT x FROM t ORDER BY x LIMIT 1), run on four engines: SQLite 3.45.1 1; PostgreSQL 16.15 1; MySQL 8.0.46 error: This version of MySQL doesn&#39;t yet support &#39;LIMIT &amp;amp; IN/ALL/ANY/SOME subquery&#39;; MariaDB 10.11.14 error: This version of MariaDB doesn&#39;t yet support &#39;LIMIT &amp;amp; IN/ALL/ANY/SOME subquery&#39;.&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Only SQLite Lets WHERE Use a Name From the Select List</title>
      <link>https://baresql.com/only-sqlite-lets-where-use-a-name-from-the-select-list/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/only-sqlite-lets-where-use-a-name-from-the-select-list/</guid>
      <description>&lt;p&gt;A query that names &lt;code&gt;price * quantity&lt;/code&gt; as total in the select list and then filters on total in WHERE runs on SQLite. PostgreSQL, MySQL and MariaDB refuse it, since the table has no column named total.&lt;/p&gt;&#xA;&lt;p&gt;WHERE is worked out before the select list, so in standard SQL the y of SELECT x * 2 AS y does not exist yet. SQLite looks it up anyway.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://baresql.com/images/rule-alias-in-where.png&#34; alt=&#34;SELECT x * 2 AS y FROM t WHERE y &amp;gt; 2, run on four engines: SQLite 3.45.1 4; PostgreSQL 16.15 error: column &amp;quot;y&amp;quot; does not exist; MySQL 8.0.46 error: Unknown column &#39;y&#39; in &#39;where clause&#39;; MariaDB 10.11.14 error: Unknown column &#39;y&#39; in &#39;WHERE&#39;.&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>PostgreSQL Refuses Select List Names in HAVING</title>
      <link>https://baresql.com/postgresql-refuses-select-list-names-in-having/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/postgresql-refuses-select-list-names-in-having/</guid>
      <description>&lt;p&gt;A report of repeat customers names its count of orders n in the select list and filters on that name in HAVING. SQLite, MySQL and MariaDB run it, and PostgreSQL refuses the query.&lt;/p&gt;&#xA;&lt;p&gt;PostgreSQL looks up names in HAVING among the table’s columns only, so HAVING n &amp;gt; 1 fails when n is the name of COUNT(*).&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://baresql.com/images/rule-alias-in-having.png&#34; alt=&#34;SELECT a, COUNT(*) AS n FROM t GROUP BY a HAVING n &amp;gt; 1, run on four engines: SQLite 3.45.1 1, 2; PostgreSQL 16.15 error: column &amp;quot;n&amp;quot; does not exist; MySQL 8.0.46 1, 2; MariaDB 10.11.14 1, 2.&#34;&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
