{"id":111015,"date":"2026-05-26T09:40:48","date_gmt":"2026-05-26T09:40:48","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?post_type=collection&#038;p=111015"},"modified":"2026-05-26T09:44:50","modified_gmt":"2026-05-26T09:44:50","slug":"the-complete-guide-to-sql-in-cosmos-db","status":"publish","type":"collection","link":"https:\/\/www.red-gate.com\/simple-talk\/collections\/the-complete-guide-to-sql-in-cosmos-db\/","title":{"rendered":"The complete guide to SQL in Cosmos DB"},"content":{"rendered":"\n<p><strong>Cosmos DB is a multi-model NoSQL database. However, one of the models it handles &#8211; the document database &#8211; <em>can<\/em> be queried using SQL. This is the complete multi-series guide to SQL in Cosmos DB, covering everything you need to know.<\/strong><\/p>\n\n\n\n<section id=\"articles-list-block_b99d96ff6b81d0f50117ec201da09af9\" class=\"articles-list my-5xl\">\n    <div class=\"grid gap-3xl\">\n        <div class=\"@container\">\n    <article class=\"flex gap-2xl items-center flex-col @md:flex-row-reverse\">\n        <div class=\"w-full @md:w-1\/3 flex items-center justify-center peer\">\n            <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/nosql\/cosmosdb\/sql-for-cosmos-db-handling-complex-json-structures\/\" aria-label=\"Cosmos DB SQL: Querying Complex JSON &#8211; Arrays, Schema on Read, and Subqueries\" class=\"no-underline relative aspect-3\/2 bg-gray-100 border border-gray-100 dark:border-gray-800 flex items-center justify-center flex-col gap-md w-full p-md\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"font-display-slab text-2xl text-base-black text-center w-full hyphens-auto\">CosmosDB<\/span>\n\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" class=\"w-24\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/themes\/simple-talk-theme-2024\/assets\/images\/logos\/st-logo.svg\" alt=\"Simple-Talk Logo\" width=\"153\" height=\"33\">\n\t\t\t<\/a>        <\/div>\n        <div class=\"w-full @md:w-2\/3 overflow-auto group\/content-text\">\n            \n<div class=\"block mb-md align-middle\">\n            \n        <a\n        href=\"https:\/\/www.red-gate.com\/simple-talk\/author\/adam-aspin\/\"\n        class=\"group\/author inline align-middle no-style min-w-fit\"\n        rel=\"author\"\n    >\n        <img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2016\/06\/Adam-Aspin.png\"\n            alt=\"Image of author: Adam Aspin\" \n            class=\"rounded-full align-middle w-6 h-6 duration-200 inline-block object-cover\"\/>\n        <span class=\"group-hover\/author:text-brand-600 peer\/ftr-image:text-brand-600 group-hover\/author:dark:text-brand-400 peer\/ftr-image:dark:text-brand-400 group-hover\/author:underline min-w-fit align-middle duration-200\">Adam Aspin<\/span>\n    <\/a>\n\n        <span class=\"card__categories align-middle\">\n                                                        <span class=\"text-gray-600 align-middle dark:text-gray-400\">in<\/span>\n                    <a\n                    class=\"inline align-middle no-underline hover:text-brand-600 hover:dark:text-brand-400 hover:underline\"\n                    href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/nosql\/cosmosdb\/\">\n                            CosmosDB                    <\/a>\n                                        <\/span>\n<\/div>\n<a class=\"no-underline group\/content-text-lower\" href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/nosql\/cosmosdb\/sql-for-cosmos-db-handling-complex-json-structures\/ \">\n    <div>\n        <h1 class=\"\n            duration-200 mt-0 mb-1 text-xl\n            \n            peer-hover:group-[]\/content-text:text-brand-600\n            group-hover\/content-text-lower:text-brand-600\n\n            peer-hover:group-[]\/content-text:dark:text-brand-400\n            group-hover\/content-text-lower:dark:text-brand-400\n            \n            peer-hover:group-[]\/content-text:underline\n            group-hover\/content-text-lower:underline\n            \n        \">\n            Cosmos DB SQL: Querying Complex JSON &#8211; Arrays, Schema on Read, and Subqueries        <\/h1>\n                    <p class=\"mb-0\">\n                Query complex JSON in Azure Cosmos DB SQL: access subnodes and arrays, handle schema-on-read inconsistencies, detect missing attributes, check data&#8230;            <\/p>\n            <\/div>\n            <div class=\"flex items-center gap-1 mt-md\">\n            <time>13 May 2019<\/time>\n            <span class=\"w-1 h-1 bg-current\tinline-block my-auto rounded-full\"><\/span>\n            <span>16 min read<\/span>\n                    <\/div>\n    <\/a>        <\/div>\n    <\/article>\n<\/div>\n\n\n<div class=\"@container\">\n    <article class=\"flex gap-2xl items-center flex-col @md:flex-row-reverse\">\n        <div class=\"w-full @md:w-1\/3 flex items-center justify-center peer\">\n            <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/nosql\/cosmosdb\/sql-for-cosmos-db-tips-and-tricks\/\" aria-label=\"Cosmos DB SQL Workarounds: LEFT, RIGHT, YEAR, MONTH, DAY, and Wildcard Search via SUBSTRING and String Functions\" class=\"no-underline relative aspect-3\/2 bg-gray-100 border border-gray-100 dark:border-gray-800 flex items-center justify-center flex-col gap-md w-full p-md\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"font-display-slab text-2xl text-base-black text-center w-full hyphens-auto\">CosmosDB<\/span>\n\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" class=\"w-24\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/themes\/simple-talk-theme-2024\/assets\/images\/logos\/st-logo.svg\" alt=\"Simple-Talk Logo\" width=\"153\" height=\"33\">\n\t\t\t<\/a>        <\/div>\n        <div class=\"w-full @md:w-2\/3 overflow-auto group\/content-text\">\n            \n<div class=\"block mb-md align-middle\">\n            \n        <a\n        href=\"https:\/\/www.red-gate.com\/simple-talk\/author\/adam-aspin\/\"\n        class=\"group\/author inline align-middle no-style min-w-fit\"\n        rel=\"author\"\n    >\n        <img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2016\/06\/Adam-Aspin.png\"\n            alt=\"Image of author: Adam Aspin\" \n            class=\"rounded-full align-middle w-6 h-6 duration-200 inline-block object-cover\"\/>\n        <span class=\"group-hover\/author:text-brand-600 peer\/ftr-image:text-brand-600 group-hover\/author:dark:text-brand-400 peer\/ftr-image:dark:text-brand-400 group-hover\/author:underline min-w-fit align-middle duration-200\">Adam Aspin<\/span>\n    <\/a>\n\n        <span class=\"card__categories align-middle\">\n                                                        <span class=\"text-gray-600 align-middle dark:text-gray-400\">in<\/span>\n                    <a\n                    class=\"inline align-middle no-underline hover:text-brand-600 hover:dark:text-brand-400 hover:underline\"\n                    href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/nosql\/cosmosdb\/\">\n                            CosmosDB                    <\/a>\n                                        <\/span>\n<\/div>\n<a class=\"no-underline group\/content-text-lower\" href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/nosql\/cosmosdb\/sql-for-cosmos-db-tips-and-tricks\/ \">\n    <div>\n        <h1 class=\"\n            duration-200 mt-0 mb-1 text-xl\n            \n            peer-hover:group-[]\/content-text:text-brand-600\n            group-hover\/content-text-lower:text-brand-600\n\n            peer-hover:group-[]\/content-text:dark:text-brand-400\n            group-hover\/content-text-lower:dark:text-brand-400\n            \n            peer-hover:group-[]\/content-text:underline\n            group-hover\/content-text-lower:underline\n            \n        \">\n            Cosmos DB SQL Workarounds: LEFT, RIGHT, YEAR, MONTH, DAY, and Wildcard Search via SUBSTRING and String Functions        <\/h1>\n                    <p class=\"mb-0\">\n                Practical workarounds for common T-SQL idioms in Azure Cosmos DB SQL API &#8211; wildcard searches using CONTAINS and STARTSWITH, null&#8230;            <\/p>\n            <\/div>\n            <div class=\"flex items-center gap-1 mt-md\">\n            <time>03 April 2019<\/time>\n            <span class=\"w-1 h-1 bg-current\tinline-block my-auto rounded-full\"><\/span>\n            <span>10 min read<\/span>\n                    <\/div>\n    <\/a>        <\/div>\n    <\/article>\n<\/div>\n\n\n<div class=\"@container\">\n    <article class=\"flex gap-2xl items-center flex-col @md:flex-row-reverse\">\n        <div class=\"w-full @md:w-1\/3 flex items-center justify-center peer\">\n            <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/nosql\/cosmosdb\/introduction-to-sql-for-cosmos-db\/\" aria-label=\"Introduction to SQL for Cosmos DB\" class=\"no-underline relative aspect-3\/2 bg-gray-100 border border-gray-100 dark:border-gray-800 flex items-center justify-center flex-col gap-md w-full p-md\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"font-display-slab text-2xl text-base-black text-center w-full hyphens-auto\">CosmosDB<\/span>\n\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" class=\"w-24\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/themes\/simple-talk-theme-2024\/assets\/images\/logos\/st-logo.svg\" alt=\"Simple-Talk Logo\" width=\"153\" height=\"33\">\n\t\t\t<\/a>        <\/div>\n        <div class=\"w-full @md:w-2\/3 overflow-auto group\/content-text\">\n            \n<div class=\"block mb-md align-middle\">\n            \n        <a\n        href=\"https:\/\/www.red-gate.com\/simple-talk\/author\/adam-aspin\/\"\n        class=\"group\/author inline align-middle no-style min-w-fit\"\n        rel=\"author\"\n    >\n        <img decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2016\/06\/Adam-Aspin.png\"\n            alt=\"Image of author: Adam Aspin\" \n            class=\"rounded-full align-middle w-6 h-6 duration-200 inline-block object-cover\"\/>\n        <span class=\"group-hover\/author:text-brand-600 peer\/ftr-image:text-brand-600 group-hover\/author:dark:text-brand-400 peer\/ftr-image:dark:text-brand-400 group-hover\/author:underline min-w-fit align-middle duration-200\">Adam Aspin<\/span>\n    <\/a>\n\n        <span class=\"card__categories align-middle\">\n                                                        <span class=\"text-gray-600 align-middle dark:text-gray-400\">in<\/span>\n                    <a\n                    class=\"inline align-middle no-underline hover:text-brand-600 hover:dark:text-brand-400 hover:underline\"\n                    href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/nosql\/cosmosdb\/\">\n                            CosmosDB                    <\/a>\n                                        <\/span>\n<\/div>\n<a class=\"no-underline group\/content-text-lower\" href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/nosql\/cosmosdb\/introduction-to-sql-for-cosmos-db\/ \">\n    <div>\n        <h1 class=\"\n            duration-200 mt-0 mb-1 text-xl\n            \n            peer-hover:group-[]\/content-text:text-brand-600\n            group-hover\/content-text-lower:text-brand-600\n\n            peer-hover:group-[]\/content-text:dark:text-brand-400\n            group-hover\/content-text-lower:dark:text-brand-400\n            \n            peer-hover:group-[]\/content-text:underline\n            group-hover\/content-text-lower:underline\n            \n        \">\n            Introduction to SQL for Cosmos DB        <\/h1>\n                    <p class=\"mb-0\">\n                This article by Adam Aspin reviews the Azure Cosmos DB SQL API from the perspective of the relational database developer&#8230;.            <\/p>\n            <\/div>\n            <div class=\"flex items-center gap-1 mt-md\">\n            <time>06 March 2019<\/time>\n            <span class=\"w-1 h-1 bg-current\tinline-block my-auto rounded-full\"><\/span>\n            <span>22 min read<\/span>\n                    <\/div>\n    <\/a>        <\/div>\n    <\/article>\n<\/div>\n\n\n            <\/div>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Cosmos DB is a multi-model NoSQL database. However, one of the models it handles &#8211; the document database &#8211; can be queried using SQL. This is the complete multi-series guide to SQL in Cosmos DB, covering everything you need to know.&hellip;<\/p>\n","protected":false},"author":2181,"featured_media":0,"template":"","tags":[159397,159398,5619,4150],"coauthors":[12351],"class_list":["post-111015","collection","type-collection","status-publish","hentry","tag-cosmos-db","tag-guidetocosmosdb","tag-nosql","tag-sql"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/collection\/111015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/collection"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/collection"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/2181"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=111015"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=111015"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=111015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}