{"id":7052,"date":"2018-08-28T08:13:07","date_gmt":"2018-08-28T15:13:07","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=7052"},"modified":"2024-01-04T06:45:48","modified_gmt":"2024-01-04T13:45:48","slug":"mysql-last_value-function","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/","title":{"rendered":"MySQL LAST_VALUE Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the MySQL <code>LAST_VALUE()<\/code> function to return the last row in an ordered set of rows.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL LAST_VALUE()\u00a0Function Overview<\/h2>\n\n\n\n<p>The <code>LAST_VALUE()<\/code> function is a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/\">window function<\/a> that allows you to select the last row in an ordered set of rows.<\/p>\n\n\n\n<p>The following shows the syntax of the <code>LAST_VALUE()<\/code> function:<\/p>\n\n\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 (\n   &#91;partition_clause]\n   &#91;order_clause]\n   &#91;frame_clause]\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>\n\n\n<p>The <code>LAST_VALUE()<\/code> function returns the value of the <code>expression<\/code> from the last row of a sorted set of rows.<\/p>\n\n\n\n<p>The <code>OVER<\/code> clause has three clauses: <code>partition_clause<\/code>, <code>order_clause<\/code>, and <code>frame_clause<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">partition_clause<\/h3>\n\n\n\n<p>The <code>partition_clause<\/code> has the following syntax:<\/p>\n\n\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>\n\n\n<p>The <code>PARTITION BY<\/code> clause distributes the result sets into multiple partitions specified by one or more expressions <code>expr1<\/code>, <code>expr2<\/code>, etc. The <code>LAST_VALUE()<\/code> function is applied to each partition independently.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">order_clause<\/h3>\n\n\n\n<p>The <code>order_clause<\/code> has the following syntax:<\/p>\n\n\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],...<\/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>\n\n\n<p>The <code>ORDER BY<\/code> clause specifies the logical orders of the rows in the partitions on which the <code>LAST_VALUE()<\/code> function operates.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u00a0frame_clause<\/h3>\n\n\n\n<p>The <code>frame_clause<\/code> defines the subset of the current partition to which the <code>LAST_VALUE()<\/code> function applies. For more detailed information on the <code>frame_clause<\/code>, please check out the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/\">window functions tutorial<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL LAST_VALUE() function examples<\/h2>\n\n\n\n<p>Let&#8217;s set up a sample table for demonstration.<\/p>\n\n\n\n<p>The following is the script to create the <code>overtime<\/code> table and populate data into the table.<\/p>\n\n\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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> overtime (\n    employee_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    department <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    <span class=\"hljs-keyword\">hours<\/span> <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n     PRIMARY <span class=\"hljs-keyword\">KEY<\/span> (employee_name , department)\n);\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> overtime(employee_name, department, <span class=\"hljs-keyword\">hours<\/span>)\n<span class=\"hljs-keyword\">VALUES<\/span>(<span class=\"hljs-string\">'Diane Murphy'<\/span>,<span class=\"hljs-string\">'Accounting'<\/span>,<span class=\"hljs-number\">37<\/span>),\n(<span class=\"hljs-string\">'Mary Patterson'<\/span>,<span class=\"hljs-string\">'Accounting'<\/span>,<span class=\"hljs-number\">74<\/span>),\n(<span class=\"hljs-string\">'Jeff Firrelli'<\/span>,<span class=\"hljs-string\">'Accounting'<\/span>,<span class=\"hljs-number\">40<\/span>),\n(<span class=\"hljs-string\">'William Patterson'<\/span>,<span class=\"hljs-string\">'Finance'<\/span>,<span class=\"hljs-number\">58<\/span>),\n(<span class=\"hljs-string\">'Gerard Bondur'<\/span>,<span class=\"hljs-string\">'Finance'<\/span>,<span class=\"hljs-number\">47<\/span>),\n(<span class=\"hljs-string\">'Anthony Bow'<\/span>,<span class=\"hljs-string\">'Finance'<\/span>,<span class=\"hljs-number\">66<\/span>),\n(<span class=\"hljs-string\">'Leslie Jennings'<\/span>,<span class=\"hljs-string\">'IT'<\/span>,<span class=\"hljs-number\">90<\/span>),\n(<span class=\"hljs-string\">'Leslie Thompson'<\/span>,<span class=\"hljs-string\">'IT'<\/span>,<span class=\"hljs-number\">88<\/span>),\n(<span class=\"hljs-string\">'Julie Firrelli'<\/span>,<span class=\"hljs-string\">'Sales'<\/span>,<span class=\"hljs-number\">81<\/span>),\n(<span class=\"hljs-string\">'Steve Patterson'<\/span>,<span class=\"hljs-string\">'Sales'<\/span>,<span class=\"hljs-number\">29<\/span>),\n(<span class=\"hljs-string\">'Foon Yue Tseng'<\/span>,<span class=\"hljs-string\">'Sales'<\/span>,<span class=\"hljs-number\">65<\/span>),\n(<span class=\"hljs-string\">'George Vanauf'<\/span>,<span class=\"hljs-string\">'Marketing'<\/span>,<span class=\"hljs-number\">89<\/span>),\n(<span class=\"hljs-string\">'Loui Bondur'<\/span>,<span class=\"hljs-string\">'Marketing'<\/span>,<span class=\"hljs-number\">49<\/span>),\n(<span class=\"hljs-string\">'Gerard Hernandez'<\/span>,<span class=\"hljs-string\">'Marketing'<\/span>,<span class=\"hljs-number\">66<\/span>),\n(<span class=\"hljs-string\">'Pamela Castillo'<\/span>,<span class=\"hljs-string\">'SCM'<\/span>,<span class=\"hljs-number\">96<\/span>),\n(<span class=\"hljs-string\">'Larry Bott'<\/span>,<span class=\"hljs-string\">'SCM'<\/span>,<span class=\"hljs-number\">100<\/span>),\n(<span class=\"hljs-string\">'Barry Jones'<\/span>,<span class=\"hljs-string\">'SCM'<\/span>,<span class=\"hljs-number\">65<\/span>);\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>\n\n\n<h3 class=\"wp-block-heading\">1) Using MySQL LAST_VALUE() function over the whole query result example<\/h3>\n\n\n\n<p>The following statement gets the employee name, overtime, and the employee who has the highest overtime:<\/p>\n\n\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\"><span class=\"hljs-keyword\">SELECT<\/span>\n    employee_name,\n    <span class=\"hljs-keyword\">hours<\/span>,\n    <span class=\"hljs-keyword\">LAST_VALUE<\/span>(employee_name) <span class=\"hljs-keyword\">OVER<\/span> (\n        <span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-keyword\">hours<\/span>\n        <span class=\"hljs-keyword\">RANGE<\/span> <span class=\"hljs-keyword\">BETWEEN<\/span>\n            <span class=\"hljs-keyword\">UNBOUNDED<\/span> <span class=\"hljs-keyword\">PRECEDING<\/span> <span class=\"hljs-keyword\">AND<\/span>\n            <span class=\"hljs-keyword\">UNBOUNDED<\/span> <span class=\"hljs-keyword\">FOLLOWING<\/span>\n    ) highest_overtime_employee\n<span class=\"hljs-keyword\">FROM<\/span>\n    overtime;<\/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>\n\n\n<p>The output is:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"318\" height=\"357\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-example.png\" alt=\"MySQL LAST_VALUE function example\" class=\"wp-image-7058\" title=\"MySQL LAST_VALUE function example\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-example.png 318w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-example-178x200.png 178w\" sizes=\"auto, (max-width: 318px) 100vw, 318px\" \/><\/figure>\n\n\n\n<p>In this example, the <code>ORDER BY<\/code> clause specified the logical order of rows in the result set by hours from low to high.<\/p>\n\n\n\n<p>The default frame specification is as follows:<\/p>\n\n\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\">RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW<\/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>\n\n\n<p>It means that the frame starts at the first row and ends at the current row of the result set.<\/p>\n\n\n\n<p>Therefore, to get the employee who has the highest overtime, we changed the frame specification to the following:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" 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<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><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>\n\n\n<p>This indicates that the frame starts at the first row and ends at the last row of the result set.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2) Using MySQL LAST_VALUE() function over partitions example<\/h3>\n\n\n\n<p>The following statement finds the employee who has the highest overtime in each department:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" 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>\n    employee_name,\n    department,\n    <span class=\"hljs-keyword\">hours<\/span>,\n    <span class=\"hljs-keyword\">LAST_VALUE<\/span>(employee_name) <span class=\"hljs-keyword\">OVER<\/span> (\n\t\t<span class=\"hljs-keyword\">PARTITION<\/span> <span class=\"hljs-keyword\">BY<\/span> department\n        <span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-keyword\">hours<\/span>\n        <span class=\"hljs-keyword\">RANGE<\/span> <span class=\"hljs-keyword\">BETWEEN<\/span>\n\t    <span class=\"hljs-keyword\">UNBOUNDED<\/span> <span class=\"hljs-keyword\">PRECEDING<\/span> <span class=\"hljs-keyword\">AND<\/span>\n            <span class=\"hljs-keyword\">UNBOUNDED<\/span> <span class=\"hljs-keyword\">FOLLOWING<\/span>\n\t) most_overtime_employee\n<span class=\"hljs-keyword\">FROM<\/span>\n    overtime;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><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>\n\n\n<p>The following picture shows the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"380\" height=\"358\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-OVER-partitions-example.png\" alt=\"MySQL LAST_VALUE Function OVER partitions example\" class=\"wp-image-7056\" title=\"MySQL LAST_VALUE Function OVER partitions example\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-OVER-partitions-example.png 380w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-OVER-partitions-example-200x188.png 200w\" sizes=\"auto, (max-width: 380px) 100vw, 380px\" \/><\/figure>\n\n\n\n<p>In this example, first, the <code>PARTITION BY<\/code> clause divided the employees by departments. Then, the <code>ORDER BY<\/code> clause orders the employees in each department by overtime from low to high.<\/p>\n\n\n\n<p>The frame specification in this case is the whole partition. As a result, the <code>LAST_VALUE()<\/code> function picked the last row in each partition which was the employee who had the highest overtime.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the MySQL <code>LAST_VALUE()<\/code> function to get the last row in an ordered set of rows.<\/li>\n<\/ul>\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=\"7052\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/\"\n\t\t\t\tdata-post-title=\"MySQL 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=\"7052\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/\"\n\t\t\t\tdata-post-title=\"MySQL 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 MySQL LAST_VALUE() window function to return the last row in an ordered set of rows.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":6941,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-7052","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL LAST_VALUE() Window Function By Practical Examples<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the MySQL LAST_VALUE() window function to return the last row in an ordered set of rows.\" \/>\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.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL LAST_VALUE() Window Function By Practical Examples\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the MySQL LAST_VALUE() window function to return the last row in an ordered set of rows.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-04T13:45:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-example.png\" \/>\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.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-last_value-function\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-last_value-function\\\/\",\"name\":\"MySQL LAST_VALUE() Window Function By Practical Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-last_value-function\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-last_value-function\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/MySQL-LAST_VALUE-example.png\",\"datePublished\":\"2018-08-28T15:13:07+00:00\",\"dateModified\":\"2024-01-04T13:45:48+00:00\",\"description\":\"This tutorial shows you how to use the MySQL LAST_VALUE() window function to return the last row in an ordered set of rows.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-last_value-function\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-last_value-function\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-last_value-function\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/MySQL-LAST_VALUE-example.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/MySQL-LAST_VALUE-example.png\",\"width\":318,\"height\":357,\"caption\":\"MySQL LAST_VALUE example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-last_value-function\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Window Functions\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL LAST_VALUE Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.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":"MySQL LAST_VALUE() Window Function By Practical Examples","description":"This tutorial shows you how to use the MySQL LAST_VALUE() window function to return the last row in an ordered set of rows.","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.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/","og_locale":"en_US","og_type":"article","og_title":"MySQL LAST_VALUE() Window Function By Practical Examples","og_description":"This tutorial shows you how to use the MySQL LAST_VALUE() window function to return the last row in an ordered set of rows.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-04T13:45:48+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-example.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/","url":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/","name":"MySQL LAST_VALUE() Window Function By Practical Examples","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-example.png","datePublished":"2018-08-28T15:13:07+00:00","dateModified":"2024-01-04T13:45:48+00:00","description":"This tutorial shows you how to use the MySQL LAST_VALUE() window function to return the last row in an ordered set of rows.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-example.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-LAST_VALUE-example.png","width":318,"height":357,"caption":"MySQL LAST_VALUE example"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-last_value-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Window Functions","item":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/"},{"@type":"ListItem","position":3,"name":"MySQL LAST_VALUE Function"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=7052"}],"version-history":[{"count":1,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7052\/revisions"}],"predecessor-version":[{"id":14189,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7052\/revisions\/14189"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/6941"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=7052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}