{"id":2495,"date":"2026-05-07T05:46:51","date_gmt":"2026-05-07T05:46:51","guid":{"rendered":"https:\/\/easycodingschool.com\/?p=2495"},"modified":"2026-05-07T05:46:51","modified_gmt":"2026-05-07T05:46:51","slug":"sql-case-order-by-prioritize-jobs","status":"publish","type":"post","link":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/","title":{"rendered":"SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example"},"content":{"rendered":"<p>Sometimes a database table is not only used for storing records. It also works like a simple queue. A background worker checks the table, picks one job, locks it, processes it, and then marks it as completed or failed.<\/p>\n<p>The SQL query in this article is a good example of that pattern. It finds the next job that should run, gives some job types higher priority, sorts older jobs first, and locks the selected row so another worker does not pick the same job at the same time.<\/p>\n<h2>Query we are explaining<\/h2>\n<pre><code>SELECT *\r\nFROM jobs\r\nWHERE status IN ('pending','failed')\r\nAND (run_at IS NULL OR run_at &lt;= UTC_TIMESTAMP())\r\nORDER BY\r\n  CASE\r\n    WHEN type = 'SUBSCRIBE_JOB' THEN 0\r\n    WHEN type = 'CLAVERTAP_JOB' THEN 1\r\n    ELSE 2\r\n  END,\r\n  created_at ASC\r\nLIMIT 1\r\nFOR UPDATE;<\/code><\/pre>\n<h2>Quick answer<\/h2>\n<p>This query picks one job from the <code>jobs<\/code> table where the job is either <code>pending<\/code> or <code>failed<\/code>, and the job is ready to run now. It gives <code>SUBSCRIBE_JOB<\/code> first priority, <code>CLAVERTAP_JOB<\/code> second priority, and all other job types last priority. If multiple jobs have the same priority, the oldest job is selected first.<\/p>\n<h2>Why use CASE inside ORDER BY?<\/h2>\n<p><code>CASE<\/code> inside <code>ORDER BY<\/code> lets you create a custom sort order. Normal sorting works alphabetically or numerically. But queues often need business priority. For example, subscription jobs may be more important than analytics jobs, so they should run first even if another type was created earlier.<\/p>\n<p>In this query, the <code>CASE<\/code> expression returns a number for each job type:<\/p>\n<ul>\n<li><code>SUBSCRIBE_JOB<\/code> returns <code>0<\/code>, so it comes first.<\/li>\n<li><code>CLAVERTAP_JOB<\/code> returns <code>1<\/code>, so it comes second.<\/li>\n<li>Every other type returns <code>2<\/code>, so it comes last.<\/li>\n<\/ul>\n<h2>How the WHERE condition works<\/h2>\n<p>The first condition is:<\/p>\n<pre><code>WHERE status IN ('pending','failed')<\/code><\/pre>\n<p>This means the worker should only pick jobs that still need work. Completed jobs should not be selected again.<\/p>\n<p>The second condition is:<\/p>\n<pre><code>AND (run_at IS NULL OR run_at &lt;= UTC_TIMESTAMP())<\/code><\/pre>\n<p>This means the job is ready now. If <code>run_at<\/code> is empty, the job can run immediately. If <code>run_at<\/code> has a time, the job should only run when that time is less than or equal to the current UTC time.<\/p>\n<h2>Example jobs table<\/h2>\n<div class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>type<\/th>\n<th>status<\/th>\n<th>run_at<\/th>\n<th>created_at<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>101<\/td>\n<td>REPORT_JOB<\/td>\n<td>pending<\/td>\n<td>NULL<\/td>\n<td>10:00<\/td>\n<\/tr>\n<tr>\n<td>102<\/td>\n<td>CLAVERTAP_JOB<\/td>\n<td>pending<\/td>\n<td>NULL<\/td>\n<td>10:05<\/td>\n<\/tr>\n<tr>\n<td>103<\/td>\n<td>SUBSCRIBE_JOB<\/td>\n<td>failed<\/td>\n<td>NULL<\/td>\n<td>10:10<\/td>\n<\/tr>\n<tr>\n<td>104<\/td>\n<td>SUBSCRIBE_JOB<\/td>\n<td>pending<\/td>\n<td>tomorrow<\/td>\n<td>09:00<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Even though job <code>101<\/code> was created earlier, job <code>103<\/code> will be selected first because <code>SUBSCRIBE_JOB<\/code> has priority <code>0<\/code>. Job <code>104<\/code> will not be selected yet because its <code>run_at<\/code> time is in the future.<\/p>\n<h2>Why created_at ASC is still important<\/h2>\n<p>After the custom priority, the query sorts by:<\/p>\n<pre><code>created_at ASC<\/code><\/pre>\n<p>This prevents newer jobs from always jumping ahead of older jobs inside the same priority group. For example, if there are five <code>SUBSCRIBE_JOB<\/code> rows, the oldest one runs first. That makes the queue fairer and easier to debug.<\/p>\n<h2>What LIMIT 1 does<\/h2>\n<p><code>LIMIT 1<\/code> tells the database to return only one job. This is common in worker systems where each worker picks one job, updates its status to processing, and then runs the task.<\/p>\n<h2>What FOR UPDATE means<\/h2>\n<p><code>FOR UPDATE<\/code> locks the selected row inside a transaction. This is important when more than one worker is running. Without a lock, two workers could select the same pending job at the same time.<\/p>\n<p>A typical worker flow looks like this:<\/p>\n<ol>\n<li>Start a database transaction.<\/li>\n<li>Run the select query with <code>FOR UPDATE<\/code>.<\/li>\n<li>Update the selected job status to <code>processing<\/code>.<\/li>\n<li>Commit the transaction.<\/li>\n<li>Process the job outside or after the safe claim step.<\/li>\n<\/ol>\n<h2>Important safety note<\/h2>\n<p><code>FOR UPDATE<\/code> only works correctly when you use a transaction. If your application runs this query without starting a transaction, the lock may not protect the row in the way you expect.<\/p>\n<h2>Possible improvement for busy queues<\/h2>\n<p>If many workers run at the same time, you may also look at patterns like <code>SKIP LOCKED<\/code> in databases that support it. That can help workers skip rows already locked by another worker instead of waiting. But this depends on your database version and queue behavior.<\/p>\n<h2>Index suggestion<\/h2>\n<p>For a large jobs table, indexing matters. A useful starting point can be an index on columns used for filtering and sorting:<\/p>\n<pre><code>CREATE INDEX idx_jobs_pick_next\r\nON jobs (status, run_at, type, created_at);<\/code><\/pre>\n<p>This index may help, but the best index depends on your real data, database engine, and query plan. Always test with <code>EXPLAIN<\/code> before and after adding indexes.<\/p>\n<h2>When should you use this pattern?<\/h2>\n<p>Use this query pattern when you have a simple database-backed job queue and need priority rules. It is useful for email jobs, subscription sync jobs, CRM sync jobs, webhook retries, failed job retries, and scheduled background tasks.<\/p>\n<h2>Common mistakes<\/h2>\n<ul>\n<li>Running <code>FOR UPDATE<\/code> without a transaction.<\/li>\n<li>Not updating the job status immediately after selecting it.<\/li>\n<li>Using server local time instead of UTC time.<\/li>\n<li>Forgetting an index on a large jobs table.<\/li>\n<li>Letting failed jobs retry forever without retry limits.<\/li>\n<\/ul>\n<h2>Final takeaway<\/h2>\n<p><code>CASE<\/code> in <code>ORDER BY<\/code> is a clean way to add business priority to a SQL query. In this example, it helps the worker select the most important ready job first, while <code>created_at ASC<\/code> keeps the queue fair and <code>FOR UPDATE<\/code> helps protect the selected row from duplicate processing.<\/p>\n<h2>FAQ<\/h2>\n<h3>Can I use CASE in ORDER BY in SQL?<\/h3>\n<p>Yes. <code>CASE<\/code> can be used in <code>ORDER BY<\/code> to create custom sorting rules based on values in a column.<\/p>\n<h3>Why does SUBSCRIBE_JOB return 0?<\/h3>\n<p>Lower numbers sort first in ascending order. Returning <code>0<\/code> gives <code>SUBSCRIBE_JOB<\/code> the highest priority.<\/p>\n<h3>What does FOR UPDATE do?<\/h3>\n<p><code>FOR UPDATE<\/code> locks the selected row inside a transaction so another transaction cannot update or claim the same row at the same time.<\/p>\n<h3>Should I use UTC_TIMESTAMP?<\/h3>\n<p>Using UTC time is usually safer for background jobs because servers and users may be in different time zones.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how SQL CASE in ORDER BY can prioritize pending and failed jobs, with a real queue query, examples, and safe FOR UPDATE usage.<\/p>\n","protected":false},"author":2,"featured_media":2496,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[252],"tags":[],"class_list":["post-2495","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example - Easy Coding School<\/title>\n<meta name=\"description\" content=\"Learn how SQL CASE in ORDER BY can prioritize pending and failed jobs, with a real queue query, examples, and safe FOR UPDATE usage.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example - Easy Coding School\" \/>\n<meta property=\"og:description\" content=\"Learn how SQL CASE in ORDER BY can prioritize pending and failed jobs, with a real queue query, examples, and safe FOR UPDATE usage.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/\" \/>\n<meta property=\"og:site_name\" content=\"Easy Coding School\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-07T05:46:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2026\/05\/SQL-CASE-in-ORDER-BY_-Prioritize-Pending-Jobs-With-a-Real-Queue-Example.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"660\" \/>\n\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"EasyCoding\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"EasyCoding\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/\"},\"author\":{\"name\":\"EasyCoding\",\"@id\":\"https:\/\/easycodingschool.com\/blog\/#\/schema\/person\/8445629344b68733cee1f0e9bc5efb7a\"},\"headline\":\"SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example\",\"datePublished\":\"2026-05-07T05:46:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/\"},\"wordCount\":862,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/easycodingschool.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2026\/05\/SQL-CASE-in-ORDER-BY_-Prioritize-Pending-Jobs-With-a-Real-Queue-Example.webp\",\"articleSection\":[\"SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/\",\"url\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/\",\"name\":\"SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example - Easy Coding School\",\"isPartOf\":{\"@id\":\"https:\/\/easycodingschool.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2026\/05\/SQL-CASE-in-ORDER-BY_-Prioritize-Pending-Jobs-With-a-Real-Queue-Example.webp\",\"datePublished\":\"2026-05-07T05:46:51+00:00\",\"description\":\"Learn how SQL CASE in ORDER BY can prioritize pending and failed jobs, with a real queue query, examples, and safe FOR UPDATE usage.\",\"breadcrumb\":{\"@id\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#primaryimage\",\"url\":\"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2026\/05\/SQL-CASE-in-ORDER-BY_-Prioritize-Pending-Jobs-With-a-Real-Queue-Example.webp\",\"contentUrl\":\"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2026\/05\/SQL-CASE-in-ORDER-BY_-Prioritize-Pending-Jobs-With-a-Real-Queue-Example.webp\",\"width\":660,\"height\":350},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/easycodingschool.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/easycodingschool.com\/blog\/#website\",\"url\":\"https:\/\/easycodingschool.com\/blog\/\",\"name\":\"Easy Coding School\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/easycodingschool.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/easycodingschool.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/easycodingschool.com\/blog\/#organization\",\"name\":\"Easy Coding School\",\"url\":\"https:\/\/easycodingschool.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/easycodingschool.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2023\/07\/New-Project-10.png\",\"contentUrl\":\"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2023\/07\/New-Project-10.png\",\"width\":310,\"height\":114,\"caption\":\"Easy Coding School \"},\"image\":{\"@id\":\"https:\/\/easycodingschool.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/easycodingschool.com\/blog\/#\/schema\/person\/8445629344b68733cee1f0e9bc5efb7a\",\"name\":\"EasyCoding\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/easycodingschool.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f6cfe49d38b7efe9d5fc059e6e94333e7734eea2874bcb3bbe2fa5c408dc10e1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f6cfe49d38b7efe9d5fc059e6e94333e7734eea2874bcb3bbe2fa5c408dc10e1?s=96&d=mm&r=g\",\"caption\":\"EasyCoding\"},\"sameAs\":[\"https:\/\/easycodingschool.com\/blog\/\"],\"url\":\"https:\/\/easycodingschool.com\/blog\/author\/easycoding\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example - Easy Coding School","description":"Learn how SQL CASE in ORDER BY can prioritize pending and failed jobs, with a real queue query, examples, and safe FOR UPDATE usage.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/","og_locale":"en_US","og_type":"article","og_title":"SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example - Easy Coding School","og_description":"Learn how SQL CASE in ORDER BY can prioritize pending and failed jobs, with a real queue query, examples, and safe FOR UPDATE usage.","og_url":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/","og_site_name":"Easy Coding School","article_published_time":"2026-05-07T05:46:51+00:00","og_image":[{"width":660,"height":350,"url":"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2026\/05\/SQL-CASE-in-ORDER-BY_-Prioritize-Pending-Jobs-With-a-Real-Queue-Example.webp","type":"image\/webp"}],"author":"EasyCoding","twitter_card":"summary_large_image","twitter_misc":{"Written by":"EasyCoding","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#article","isPartOf":{"@id":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/"},"author":{"name":"EasyCoding","@id":"https:\/\/easycodingschool.com\/blog\/#\/schema\/person\/8445629344b68733cee1f0e9bc5efb7a"},"headline":"SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example","datePublished":"2026-05-07T05:46:51+00:00","mainEntityOfPage":{"@id":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/"},"wordCount":862,"commentCount":0,"publisher":{"@id":"https:\/\/easycodingschool.com\/blog\/#organization"},"image":{"@id":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#primaryimage"},"thumbnailUrl":"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2026\/05\/SQL-CASE-in-ORDER-BY_-Prioritize-Pending-Jobs-With-a-Real-Queue-Example.webp","articleSection":["SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/","url":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/","name":"SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example - Easy Coding School","isPartOf":{"@id":"https:\/\/easycodingschool.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#primaryimage"},"image":{"@id":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#primaryimage"},"thumbnailUrl":"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2026\/05\/SQL-CASE-in-ORDER-BY_-Prioritize-Pending-Jobs-With-a-Real-Queue-Example.webp","datePublished":"2026-05-07T05:46:51+00:00","description":"Learn how SQL CASE in ORDER BY can prioritize pending and failed jobs, with a real queue query, examples, and safe FOR UPDATE usage.","breadcrumb":{"@id":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#primaryimage","url":"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2026\/05\/SQL-CASE-in-ORDER-BY_-Prioritize-Pending-Jobs-With-a-Real-Queue-Example.webp","contentUrl":"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2026\/05\/SQL-CASE-in-ORDER-BY_-Prioritize-Pending-Jobs-With-a-Real-Queue-Example.webp","width":660,"height":350},{"@type":"BreadcrumbList","@id":"https:\/\/easycodingschool.com\/blog\/sql-case-order-by-prioritize-jobs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/easycodingschool.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SQL CASE in ORDER BY: Prioritize Pending Jobs With a Real Queue Example"}]},{"@type":"WebSite","@id":"https:\/\/easycodingschool.com\/blog\/#website","url":"https:\/\/easycodingschool.com\/blog\/","name":"Easy Coding School","description":"","publisher":{"@id":"https:\/\/easycodingschool.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/easycodingschool.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/easycodingschool.com\/blog\/#organization","name":"Easy Coding School","url":"https:\/\/easycodingschool.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/easycodingschool.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2023\/07\/New-Project-10.png","contentUrl":"https:\/\/easycodingschool.com\/blog\/wp-content\/uploads\/2023\/07\/New-Project-10.png","width":310,"height":114,"caption":"Easy Coding School "},"image":{"@id":"https:\/\/easycodingschool.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/easycodingschool.com\/blog\/#\/schema\/person\/8445629344b68733cee1f0e9bc5efb7a","name":"EasyCoding","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/easycodingschool.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f6cfe49d38b7efe9d5fc059e6e94333e7734eea2874bcb3bbe2fa5c408dc10e1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f6cfe49d38b7efe9d5fc059e6e94333e7734eea2874bcb3bbe2fa5c408dc10e1?s=96&d=mm&r=g","caption":"EasyCoding"},"sameAs":["https:\/\/easycodingschool.com\/blog\/"],"url":"https:\/\/easycodingschool.com\/blog\/author\/easycoding\/"}]}},"_links":{"self":[{"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/posts\/2495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2495"}],"version-history":[{"count":1,"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/posts\/2495\/revisions"}],"predecessor-version":[{"id":2497,"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/posts\/2495\/revisions\/2497"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/media\/2496"}],"wp:attachment":[{"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/easycodingschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}