{"id":7060,"date":"2018-08-28T08:47:37","date_gmt":"2018-08-28T15:47:37","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=7060"},"modified":"2024-01-04T06:47:43","modified_gmt":"2024-01-04T13:47:43","slug":"mysql-nth_value-function","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/","title":{"rendered":"MySQL NTH_VALUE Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the <code>NTH_VALUE()<\/code> function to get a value from the Nth row in a result set.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL NTH_VALUE() function<\/h2>\n\n\n\n<p>The <code>NTH_VALUE()<\/code> is a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/\">window function<\/a> that allows you to get a value from the Nth row in an ordered set of rows.<\/p>\n\n\n\n<p>The following shows the syntax of the <code>NTH_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\">NTH_VALUE(expression, N)\nFROM FIRST\nOVER (\n    partition_clause\n    order_clause\n    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>NTH_VALUE()<\/code> function returns the value of <code>expression<\/code> from the Nth row of the window frame. If that Nth row does not exist, the function returns <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-null\/\">NULL<\/a><\/code>. N must be a positive integer e.g., 1, 2, and 3.<\/p>\n\n\n\n<p>The <code>FROM FIRST<\/code> instructs the <code>NTH_VALUE()<\/code> function to begin calculation at the first row of the window frame.<\/p>\n\n\n\n<p>Note that SQL standard supports both <code>FROM FIRST<\/code> and <code>FROM LAST<\/code>. However, MySQL only supports <code>FROM FIRST<\/code>. If you want to simulate the effect of <code>FROM LAST<\/code>, then you can use the <code>ORDER BY<\/code> in the <code>over_clause<\/code> to sort the result set in reverse order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL NTH_VALUE() function examples<\/h2>\n\n\n\n<p>We will <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-create-table\/\">create a new table<\/a> named&nbsp;<code>basic_pay<\/code> for the demonstration.<\/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\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> basic_pays(\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    salary <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\n<span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> \n\tbasic_pays(employee_name, \n\t\t\t   department, \n\t\t\t   salary)\n<span class=\"hljs-keyword\">VALUES<\/span>\n\t(<span class=\"hljs-string\">'Diane Murphy'<\/span>,<span class=\"hljs-string\">'Accounting'<\/span>,<span class=\"hljs-number\">8435<\/span>),\n\t(<span class=\"hljs-string\">'Mary Patterson'<\/span>,<span class=\"hljs-string\">'Accounting'<\/span>,<span class=\"hljs-number\">9998<\/span>),\n\t(<span class=\"hljs-string\">'Jeff Firrelli'<\/span>,<span class=\"hljs-string\">'Accounting'<\/span>,<span class=\"hljs-number\">8992<\/span>),\n\t(<span class=\"hljs-string\">'William Patterson'<\/span>,<span class=\"hljs-string\">'Accounting'<\/span>,<span class=\"hljs-number\">8870<\/span>),\n\t(<span class=\"hljs-string\">'Gerard Bondur'<\/span>,<span class=\"hljs-string\">'Accounting'<\/span>,<span class=\"hljs-number\">11472<\/span>),\n\t(<span class=\"hljs-string\">'Anthony Bow'<\/span>,<span class=\"hljs-string\">'Accounting'<\/span>,<span class=\"hljs-number\">6627<\/span>),\n\t(<span class=\"hljs-string\">'Leslie Jennings'<\/span>,<span class=\"hljs-string\">'IT'<\/span>,<span class=\"hljs-number\">8113<\/span>),\n\t(<span class=\"hljs-string\">'Leslie Thompson'<\/span>,<span class=\"hljs-string\">'IT'<\/span>,<span class=\"hljs-number\">5186<\/span>),\n\t(<span class=\"hljs-string\">'Julie Firrelli'<\/span>,<span class=\"hljs-string\">'Sales'<\/span>,<span class=\"hljs-number\">9181<\/span>),\n\t(<span class=\"hljs-string\">'Steve Patterson'<\/span>,<span class=\"hljs-string\">'Sales'<\/span>,<span class=\"hljs-number\">9441<\/span>),\n\t(<span class=\"hljs-string\">'Foon Yue Tseng'<\/span>,<span class=\"hljs-string\">'Sales'<\/span>,<span class=\"hljs-number\">6660<\/span>),\n\t(<span class=\"hljs-string\">'George Vanauf'<\/span>,<span class=\"hljs-string\">'Sales'<\/span>,<span class=\"hljs-number\">10563<\/span>),\n\t(<span class=\"hljs-string\">'Loui Bondur'<\/span>,<span class=\"hljs-string\">'SCM'<\/span>,<span class=\"hljs-number\">10449<\/span>),\n\t(<span class=\"hljs-string\">'Gerard Hernandez'<\/span>,<span class=\"hljs-string\">'SCM'<\/span>,<span class=\"hljs-number\">6949<\/span>),\n\t(<span class=\"hljs-string\">'Pamela Castillo'<\/span>,<span class=\"hljs-string\">'SCM'<\/span>,<span class=\"hljs-number\">11303<\/span>),\n\t(<span class=\"hljs-string\">'Larry Bott'<\/span>,<span class=\"hljs-string\">'SCM'<\/span>,<span class=\"hljs-number\">11798<\/span>),\n\t(<span class=\"hljs-string\">'Barry Jones'<\/span>,<span class=\"hljs-string\">'SCM'<\/span>,<span class=\"hljs-number\">10586<\/span>);<\/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<h3 class=\"wp-block-heading\">1) Using MySQL NTH_VALUE() function over the result set<\/h3>\n\n\n\n<p>The following statement uses the <code>NTH_VALUE()<\/code> function to find the employee who has the second highest salary :<\/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\"><span class=\"hljs-keyword\">SELECT<\/span>\n    employee_name,\n    salary,\n    <span class=\"hljs-keyword\">NTH_VALUE<\/span>(employee_name, <span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">OVER<\/span>  (\n        <span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> salary <span class=\"hljs-keyword\">DESC<\/span>\n    ) second_highest_salary\n<span class=\"hljs-keyword\">FROM<\/span>\n    basic_pays;<\/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>Here is the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"326\" height=\"280\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-Example-1.png\" alt=\"MySQL NTH_VALUE Function Example\" class=\"wp-image-7065\" title=\"MySQL NTH_VALUE Function Example\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-Example-1.png 326w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-Example-1-200x172.png 200w\" sizes=\"auto, (max-width: 326px) 100vw, 326px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">2) Using MySQL NTH_VALUE()\u00a0over partitions example<\/h3>\n\n\n\n<p>The following query finds the employee who has the second highest salary in every department:<\/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\">SELECT<\/span>\n\temployee_name,\n\tdepartment,\n\tsalary,\n\t<span class=\"hljs-keyword\">NTH_VALUE<\/span>(employee_name, <span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">OVER<\/span>  (\n\t\t<span class=\"hljs-keyword\">PARTITION<\/span> <span class=\"hljs-keyword\">BY<\/span> department\n\t\t<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> salary <span class=\"hljs-keyword\">DESC<\/span>\n\t\t<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> <span class=\"hljs-keyword\">UNBOUNDED<\/span> <span class=\"hljs-keyword\">FOLLOWING<\/span>\n\t) second_highest_salary\n<span class=\"hljs-keyword\">FROM<\/span>\n\tbasic_pays;<\/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<p>Here is the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"406\" height=\"359\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-OVER-partition-example.png\" alt=\"MySQL NTH_VALUE Function OVER partition example\" class=\"wp-image-7063\" title=\"MySQL NTH_VALUE Function OVER partition example\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-OVER-partition-example.png 406w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-OVER-partition-example-200x177.png 200w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/figure>\n\n\n\n<p>In this query, we added the <code>PARTITION BY<\/code> clause to divide the employees by department. Then the <code>NTH_VALUE()<\/code> function is applied to each partition independently.<\/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>NTH_VALUE()<\/code> function to get a value from the Nth row of a result set.<\/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=\"7060\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/\"\n\t\t\t\tdata-post-title=\"MySQL NTH_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=\"7060\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/\"\n\t\t\t\tdata-post-title=\"MySQL NTH_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>In this tutorial, you will learn how to use the MySQL NTH_VALUE() function to get a value from the Nth row in a result set.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":6941,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-7060","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 NTH_VALUE Window Function By Practical Examples<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to use the MySQL NTH_VALUE() function to get a value from the Nth row in a result set.\" \/>\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-nth_value-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL NTH_VALUE Window Function By Practical Examples\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to use the MySQL NTH_VALUE() function to get a value from the Nth row in a result set.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-04T13:47:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-Example-1.png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 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-nth_value-function\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-nth_value-function\\\/\",\"name\":\"MySQL NTH_VALUE Window Function By Practical Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-nth_value-function\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-nth_value-function\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/MySQL-NTH_VALUE-Function-Example-1.png\",\"datePublished\":\"2018-08-28T15:47:37+00:00\",\"dateModified\":\"2024-01-04T13:47:43+00:00\",\"description\":\"In this tutorial, you will learn how to use the MySQL NTH_VALUE() function to get a value from the Nth row in a result set.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-nth_value-function\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-nth_value-function\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-nth_value-function\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/MySQL-NTH_VALUE-Function-Example-1.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/MySQL-NTH_VALUE-Function-Example-1.png\",\"width\":326,\"height\":280,\"caption\":\"MySQL NTH_VALUE Function Example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-window-functions\\\/mysql-nth_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 NTH_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 NTH_VALUE Window Function By Practical Examples","description":"In this tutorial, you will learn how to use the MySQL NTH_VALUE() function to get a value from the Nth row in a result set.","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-nth_value-function\/","og_locale":"en_US","og_type":"article","og_title":"MySQL NTH_VALUE Window Function By Practical Examples","og_description":"In this tutorial, you will learn how to use the MySQL NTH_VALUE() function to get a value from the Nth row in a result set.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-04T13:47:43+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-Example-1.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/","url":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/","name":"MySQL NTH_VALUE Window Function By Practical Examples","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-Example-1.png","datePublished":"2018-08-28T15:47:37+00:00","dateModified":"2024-01-04T13:47:43+00:00","description":"In this tutorial, you will learn how to use the MySQL NTH_VALUE() function to get a value from the Nth row in a result set.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_value-function\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-Example-1.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/08\/MySQL-NTH_VALUE-Function-Example-1.png","width":326,"height":280,"caption":"MySQL NTH_VALUE Function Example"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-window-functions\/mysql-nth_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 NTH_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\/7060","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=7060"}],"version-history":[{"count":1,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7060\/revisions"}],"predecessor-version":[{"id":14190,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7060\/revisions\/14190"}],"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=7060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}