{"id":1765,"date":"2018-09-09T01:56:08","date_gmt":"2018-09-09T08:56:08","guid":{"rendered":"https:\/\/sqltutorial.org\/?page_id=1765"},"modified":"2025-02-04T07:06:54","modified_gmt":"2025-02-04T14:06:54","slug":"sql-last_value","status":"publish","type":"page","link":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/","title":{"rendered":"SQL LAST_VALUE Function"},"content":{"rendered":"\r\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the SQL <code>LAST_VALUE()<\/code> function to return the last value in an ordered set of values.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='overview-of-the-sql-last_value-function'>Overview of the SQL LAST_VALUE() Function <a href=\"#overview-of-the-sql-last_value-function\" class=\"anchor\" id=\"overview-of-the-sql-last_value-function\" title=\"Anchor for Overview of the SQL LAST_VALUE() Function\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>The <code>LAST_VALUE()<\/code> is a window function that returns the last value in an ordered set of values.<\/p>\r\n\r\n\r\n\r\n<p>Here&#8217;s the basic syntax of the <code>LAST_VALUE()<\/code> function:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">LAST_VALUE(expression) OVER (\r\n    partition_clause\r\n    order_clause\r\n    frame_clause\r\n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>In this syntax:<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='expression'>expression <a href=\"#expression\" class=\"anchor\" id=\"expression\" title=\"Anchor for &lt;code&gt;expression&lt;\/code&gt;\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<p>The returned value of the function can be a column or an expression that results in a single value.<\/p>\r\n\r\n\r\n\r\n<p>The <code>OVER<\/code> clause consists of three clauses: <code>partition_clause<\/code>, <code>order_clause<\/code>, and <code>frame_clause<\/code>.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='partition_clause'>partition_clause <a href=\"#partition_clause\" class=\"anchor\" id=\"partition_clause\" title=\"Anchor for &lt;code&gt;partition_clause&lt;\/code&gt;\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<p>The syntax of the <code>partition_clause<\/code> clause is as follows:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">PARTITION BY expr1, expr2, ...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>The <code>PARTITION BY<\/code> clause divides the rows of the result sets into partitions to which the <code>LAST_VALUE()<\/code> function applies. Because the <code>PARTITION BY<\/code> clause is optional, if you omit it, the function treats the whole result set as a single partition.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='order_clause'>order_clause <a href=\"#order_clause\" class=\"anchor\" id=\"order_clause\" title=\"Anchor for &lt;code&gt;order_clause&lt;\/code&gt;\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<p>The <code>order_clause<\/code> clause specified the order of rows in partitions to which the <code>LAST_VALUE()<\/code> function applies. The syntax of the <code>ORDER BY<\/code> clause is as follows:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">ORDER BY expr1 &#91;ASC | DESC], expr2, ...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='frame_clause'>frame_clause <a href=\"#frame_clause\" class=\"anchor\" id=\"frame_clause\" title=\"Anchor for &lt;code&gt;frame_clause&lt;\/code&gt;\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<p>The <code>frame_clause<\/code> defines the subset (or frame) of the partition being evaluated. For detailed information on the frame clause, check out the\u00a0<a href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/\" target=\"_blank\" rel=\"noopener\">window function tutorial<\/a>.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='sql-last_value-function-examples'>SQL LAST_VALUE() function examples <a href=\"#sql-last_value-function-examples\" class=\"anchor\" id=\"sql-last_value-function-examples\" title=\"Anchor for SQL LAST_VALUE() function examples\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>We will use the following <code>employees<\/code> and <code>departments<\/code> tables from the <a href=\"https:\/\/www.sqltutorial.org\/sql-sample-database\/\">sample database<\/a> for demonstration.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"451\" height=\"269\" class=\"wp-image-1190\" title=\"Employees &amp; Departments Tables\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png\" alt=\"Employees &amp; Departments Tables\" srcset=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png 451w, https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables-300x179.png 300w\" sizes=\"auto, (max-width: 451px) 100vw, 451px\" \/><\/figure>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='using-sql-last_value-function-over-the-result-set-example'>Using SQL LAST_VALUE() function over the result set example <a href=\"#using-sql-last_value-function-over-the-result-set-example\" class=\"anchor\" id=\"using-sql-last_value-function-over-the-result-set-example\" title=\"Anchor for Using SQL LAST_VALUE() function over the result set example\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<p>The following statement finds employees who have the highest salary in the company:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\r\n    first_name,\r\n    last_name,\r\n    salary,\r\n    <span class=\"hljs-keyword\">LAST_VALUE<\/span> (first_name) <span class=\"hljs-keyword\">OVER<\/span> (\r\n        <span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> salary\r\n        <span class=\"hljs-keyword\">RANGE<\/span> <span class=\"hljs-keyword\">BETWEEN<\/span> <span class=\"hljs-keyword\">UNBOUNDED<\/span> <span class=\"hljs-keyword\">PRECEDING<\/span> <span class=\"hljs-keyword\">AND<\/span> \r\n        <span class=\"hljs-keyword\">UNBOUNDED<\/span> <span class=\"hljs-keyword\">FOLLOWING<\/span>\r\n    ) highest_salary\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n    employees;\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Here is the partial output:<\/p>\r\n\r\n\r\n\r\n<p>In this example, the <code>ORDER BY<\/code> clause sorted employees by salary and the <code>LAST_VALUE()<\/code> selected the first name of the employee who has the lowest salary.<\/p>\r\n\r\n\r\n\r\n<p>The frame clause is as follows:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>It means the frame starts at the first row (<code>UNBOUNDED PRECEDING<\/code>) and ends at the last row ( <code>UNBOUNDED FOLLOWING<\/code>) of the result set.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\" id='using-sql-last_value-over-partition-example'>Using SQL LAST_VALUE() over partition example <a href=\"#using-sql-last_value-over-partition-example\" class=\"anchor\" id=\"using-sql-last_value-over-partition-example\" title=\"Anchor for Using SQL LAST_VALUE() over partition example\">#<\/a><\/h3>\r\n\r\n\r\n\r\n<p>The following statement finds employees who have the highest salary in each department.<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\r\n    first_name,\r\n    last_name,\r\n    department_name,\r\n    salary,\r\n    <span class=\"hljs-keyword\">LAST_VALUE<\/span> (<span class=\"hljs-keyword\">CONCAT<\/span>(first_name,<span class=\"hljs-string\">' '<\/span>,last_name)) <span class=\"hljs-keyword\">OVER<\/span> (\r\n        <span class=\"hljs-keyword\">PARTITION<\/span> <span class=\"hljs-keyword\">BY<\/span> department_name\r\n        <span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> salary\r\n        <span class=\"hljs-keyword\">RANGE<\/span> <span class=\"hljs-keyword\">BETWEEN<\/span> <span class=\"hljs-keyword\">UNBOUNDED<\/span> <span class=\"hljs-keyword\">PRECEDING<\/span> <span class=\"hljs-keyword\">AND<\/span> \r\n        <span class=\"hljs-keyword\">UNBOUNDED<\/span> <span class=\"hljs-keyword\">FOLLOWING<\/span>\r\n    ) highest_salary\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n    employees e\r\n    <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> departments d \r\n        <span class=\"hljs-keyword\">ON<\/span> d.department_id = e.department_id;\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>The following picture shows the output of the query:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"434\" height=\"820\" class=\"wp-image-1766\" title=\"SQL LAST_VALUE Function Over Partition Example\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-LAST_VALUE-Function-Over-Partition-Example.png\" alt=\"SQL LAST_VALUE Function Over Partition Example\" srcset=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-LAST_VALUE-Function-Over-Partition-Example.png 434w, https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/09\/SQL-LAST_VALUE-Function-Over-Partition-Example-159x300.png 159w\" sizes=\"auto, (max-width: 434px) 100vw, 434px\" \/><\/figure>\r\n\r\n\r\n\r\n<p>Let&#8217;s examine the query in more detail:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>First, the <code>PARTITION BY<\/code> clause divided the employees by departments.<\/li>\r\n\r\n\r\n\r\n<li>Then, the <code>ORDER BY<\/code> clause sorted employees in each department by their salary in ascending order.<\/li>\r\n\r\n\r\n\r\n<li>Finally, the <code>LAST_VALUE()<\/code> is applied to sorted rows in each partition. Because the frame starts at the first row and ends at the last row of each partition, the <code>LAST_VALUE()<\/code> selected the employee who has the highest salary.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>In this tutorial, you have learned how to use the SQL <code>LAST_VALUE()<\/code> function to get the last value in an ordered set of values.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='databases'>Databases <a href=\"#databases\" class=\"anchor\" id=\"databases\" title=\"Anchor for Databases\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><a href=\"https:\/\/www.pgtutorial.com\/postgresql-window-functions\/postgresql-last_value\/\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL LAST_VALUE function<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.oracletutorial.com\/oracle-analytic-functions\/oracle-last_value\/\" target=\"_blank\" rel=\"noreferrer noopener\">Oracle LAST_VALUE function<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-window-functions\/sql-server-lag-function\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQL Server LAST_VALUE function<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-window-functions\/sqlite-last_value\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQLite LAST_VALUE function<\/a><\/li>\r\n\r\n\r\n\r\n<li><a href=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/\" target=\"_blank\" rel=\"noreferrer noopener\">MySQL LAST_VALUE function<\/a><\/li>\r\n<\/ul>\r\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1765\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/\"\n\t\t\t\tdata-post-title=\"SQL LAST_VALUE Function\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1765\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/\"\n\t\t\t\tdata-post-title=\"SQL LAST_VALUE Function\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows you how to use the SQL LAST_VALUE() function to get last value in an ordered set of values.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1707,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1765","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL LAST_VALUE Function<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the SQL LAST_VALUE() function to get last value in an ordered set of values.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL LAST_VALUE Function\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the SQL LAST_VALUE() function to get last value in an ordered set of values.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-04T14:06:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png\" \/>\n\t<meta property=\"og:image:width\" content=\"451\" \/>\n\t<meta property=\"og:image:height\" content=\"269\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/\",\"url\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/\",\"name\":\"SQL LAST_VALUE Function\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqltutorial.org\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png\",\"datePublished\":\"2018-09-09T08:56:08+00:00\",\"dateModified\":\"2025-02-04T14:06:54+00:00\",\"description\":\"This tutorial shows you how to use the SQL LAST_VALUE() function to get last value in an ordered set of values.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/#primaryimage\",\"url\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png\",\"contentUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png\",\"width\":451,\"height\":269,\"caption\":\"Employees & Departments Tables\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqltutorial.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Window Functions\",\"item\":\"https:\/\/www.sqltutorial.org\/sql-window-functions\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL LAST_VALUE Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqltutorial.org\/#website\",\"url\":\"https:\/\/www.sqltutorial.org\/\",\"name\":\"SQL Tutorial\",\"description\":\"An Interactive SQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqltutorial.org\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL LAST_VALUE Function","description":"This tutorial shows you how to use the SQL LAST_VALUE() function to get last value in an ordered set of values.","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:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/","og_locale":"en_US","og_type":"article","og_title":"SQL LAST_VALUE Function","og_description":"This tutorial shows you how to use the SQL LAST_VALUE() function to get last value in an ordered set of values.","og_url":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/","og_site_name":"SQL Tutorial","article_modified_time":"2025-02-04T14:06:54+00:00","og_image":[{"width":451,"height":269,"url":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/","url":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/","name":"SQL LAST_VALUE Function","isPartOf":{"@id":"https:\/\/www.sqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/#primaryimage"},"image":{"@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png","datePublished":"2018-09-09T08:56:08+00:00","dateModified":"2025-02-04T14:06:54+00:00","description":"This tutorial shows you how to use the SQL LAST_VALUE() function to get last value in an ordered set of values.","breadcrumb":{"@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/#primaryimage","url":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png","contentUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/employees_departments_tables.png","width":451,"height":269,"caption":"Employees & Departments Tables"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqltutorial.org\/sql-window-functions\/sql-last_value\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"SQL Window Functions","item":"https:\/\/www.sqltutorial.org\/sql-window-functions\/"},{"@type":"ListItem","position":3,"name":"SQL LAST_VALUE Function"}]},{"@type":"WebSite","@id":"https:\/\/www.sqltutorial.org\/#website","url":"https:\/\/www.sqltutorial.org\/","name":"SQL Tutorial","description":"An Interactive SQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/1765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/comments?post=1765"}],"version-history":[{"count":0,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/1765\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/1707"}],"wp:attachment":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/media?parent=1765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}