<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>NULL and Sorting on BareSQL.com</title>
    <link>https://baresql.com/tags/null-and-sorting/</link>
    <description>Recent content in NULL and Sorting 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/null-and-sorting/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>GREATEST Skips NULL on PostgreSQL and Returns NULL on MySQL</title>
      <link>https://baresql.com/greatest-skips-null-on-postgresql-and-returns-null-on-mysql/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/greatest-skips-null-on-postgresql-and-returns-null-on-mysql/</guid>
      <description>&lt;p&gt;&lt;code&gt;GREATEST(sale_price, list_price)&lt;/code&gt; picks the larger of two prices. When one of them is NULL, PostgreSQL still picks the other price, and no other engine does.&lt;/p&gt;&#xA;&lt;p&gt;GREATEST(1, NULL) is 1 on PostgreSQL and NULL on MySQL and MariaDB. SQLite has the same idea under the names MAX(a, b) and MIN(a, b) with two or more arguments; they return NULL when any argument is NULL, and the other engines read MAX and MIN as aggregates.&lt;/p&gt;</description>
    </item>
    <item>
      <title>NULL Sorts First on SQLite and MySQL and Last on PostgreSQL</title>
      <link>https://baresql.com/null-sorts-first-on-sqlite-and-mysql-and-last-on-postgresql/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/null-sorts-first-on-sqlite-and-mysql-and-last-on-postgresql/</guid>
      <description>&lt;p&gt;Sort customers by the date of their last order and the ones who never ordered come first on SQLite, MySQL and MariaDB and last on PostgreSQL. The first page of the same report shows different people.&lt;/p&gt;&#xA;&lt;p&gt;The standard leaves the place of NULL in ORDER BY to the engine. PostgreSQL treats NULL as larger than every value, the others as smaller, and descending order turns both around. Paged results change when the column holds NULL, and so do window functions such as ROW_NUMBER() OVER (ORDER BY x).&lt;/p&gt;</description>
    </item>
    <item>
      <title>NULLS FIRST and NULLS LAST Fail on MySQL and MariaDB</title>
      <link>https://baresql.com/nulls-first-and-nulls-last-fail-on-mysql-and-mariadb/</link>
      <pubDate>Mon, 26 Oct 2026 00:00:00 +0000</pubDate>
      <guid>https://baresql.com/nulls-first-and-nulls-last-fail-on-mysql-and-mariadb/</guid>
      <description>&lt;p&gt;&lt;code&gt;ORDER BY shipped_at NULLS LAST&lt;/code&gt; is the tidy way to put unshipped orders at the end on PostgreSQL and SQLite. MySQL and MariaDB have no such syntax and refuse the query.&lt;/p&gt;&#xA;&lt;p&gt;SQLite added them in version 3.30. MySQL and MariaDB have no syntax for choosing where NULL sorts.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://baresql.com/images/rule-nulls-first-last.png&#34; alt=&#34;SELECT x FROM t ORDER BY x NULLS LAST, run on four engines: SQLite 3.45.1 1; 2; NULL; PostgreSQL 16.15 1; 2; NULL; MySQL 8.0.46 error: You have an error in your SQL syntax ... near &#39;NULLS LAST&#39; at line 1; MariaDB 10.11.14 error: You have an error in your SQL syntax ... near &#39;NULLS LAST&#39; at line 1.&#34;&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
