{"id":176,"date":"2018-04-13T11:39:50","date_gmt":"2018-04-13T04:39:50","guid":{"rendered":"http:\/\/www.sqlservertutorial.net\/?page_id=176"},"modified":"2024-09-24T21:05:31","modified_gmt":"2024-09-24T14:05:31","slug":"sql-server-select-distinct","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/","title":{"rendered":"SQL Server SELECT DISTINCT"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the SQL Server <code>SELECT DISTINCT<\/code> clause to return distinct rows from a result set.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-sql-server-select-distinct-clause'>Introduction to SQL Server SELECT DISTINCT clause <a href=\"#introduction-to-sql-server-select-distinct-clause\" class=\"anchor\" id=\"introduction-to-sql-server-select-distinct-clause\" title=\"Anchor for Introduction to SQL Server SELECT DISTINCT clause\">#<\/a><\/h2>\n\n\n\n<p>Sometimes, you may want to get only distinct values in a specified column of a table. To achieve this, you can use the <code>SELECT DISTINCT<\/code> clause. <\/p>\n\n\n\n<p>Here&#8217;s how you can do it:<\/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\"><span class=\"hljs-keyword\">SELECT<\/span> \n  <span class=\"hljs-keyword\">DISTINCT<\/span> column_name \n<span class=\"hljs-keyword\">FROM<\/span> \n  table_name;<\/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 query will return unique values from the column <code>column_name<\/code>. In other words, it removes duplicate values from the <code>column_name<\/code> in the result set.<\/p>\n\n\n\n<p>If you use the <code>DISTINCT<\/code> clause with multiple columns as follows:<\/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\">SELECT<\/span> <span class=\"hljs-keyword\">DISTINCT<\/span>\n\tcolumn_name1,\n\tcolumn_name2 ,\n\t...\n<span class=\"hljs-keyword\">FROM<\/span>\n\ttable_name;<\/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 query will evaluate the uniqueness based on the combination of values in all the specified columns in the <code>SELECT<\/code> list. It will return only rows with unique combinations of the specified columns.<\/p>\n\n\n\n<p>When you apply the <code>DISTINCT<\/code> clause to a column that contains NULLs, it will keep only one NULL and eliminate the others. In other words, the <code>DISTINCT<\/code> clause treats all NULLs as the same value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-server-select-distinct-examples'>SQL Server SELECT DISTINCT examples <a href=\"#sql-server-select-distinct-examples\" class=\"anchor\" id=\"sql-server-select-distinct-examples\" title=\"Anchor for SQL Server SELECT DISTINCT examples\">#<\/a><\/h2>\n\n\n\n<p>We will use the <code>customers<\/code> table from the <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/\">sample database<\/a> for the demonstration:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/customers.png\" alt=\"\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='1-using-the-select-distinct-with-one-column'>1) Using the SELECT DISTINCT with one column <a href=\"#1-using-the-select-distinct-with-one-column\" class=\"anchor\" id=\"1-using-the-select-distinct-with-one-column\" title=\"Anchor for 1) Using the SELECT DISTINCT with one column\">#<\/a><\/h3>\n\n\n\n<p>The following statement uses the <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select\/\">SELECT<\/a> statement to retrieve all cities of all customers from the <code>customers<\/code> tables:<\/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  city \n<span class=\"hljs-keyword\">FROM<\/span> \n  sales.customers \n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> \n  city;<\/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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"107\" height=\"172\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-SELECT-DISTINCT-duplicate-cities.png\" alt=\"SQL Server SELECT DISTINCT - duplicate cities\" class=\"wp-image-196\"\/><\/figure>\n\n\n\n<p>The output indicates that the cities&nbsp;are duplicates.<\/p>\n\n\n\n<p>To retrieve only distinct cities, you can use the <code>SELECT DISTINCT<\/code> keyword as follows:<\/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  <span class=\"hljs-keyword\">DISTINCT<\/span> city \n<span class=\"hljs-keyword\">FROM<\/span> \n  sales.customers \n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> \n  city;<\/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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"77\" height=\"171\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-SELECT-DISTINCT-distinct-cities.png\" alt=\"SQL Server SELECT DISTINCT - distinct cities\" class=\"wp-image-195\"\/><\/figure>\n\n\n\n<p>The output shows that the <code>SELECT DISTINCT<\/code> returns only distinct cities without duplicates.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='2-using-select-distinct-with-multiple-columns'>2) Using SELECT DISTINCT with multiple columns <a href=\"#2-using-select-distinct-with-multiple-columns\" class=\"anchor\" id=\"2-using-select-distinct-with-multiple-columns\" title=\"Anchor for 2) Using SELECT DISTINCT with multiple columns\">#<\/a><\/h3>\n\n\n\n<p>The following example uses the <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select\/\">SELECT<\/a> statement to retrieve the cities and states of all customers from the <code>customers<\/code> table:<\/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  city, \n  state \n<span class=\"hljs-keyword\">FROM<\/span> \n  sales.customers \n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> \n  city, \n  state;<\/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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"110\" height=\"267\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-SELECT-DISTINCT-multiple-columns-example-before.png\" alt=\"SQL Server SELECT DISTINCT - multiple columns example before\" class=\"wp-image-1999\"\/><\/figure>\n\n\n\n<p>The output indicates that there are duplicate cities &amp; states, for example, <code>Albany NY<\/code>, <code>Amarillo TX<\/code>, and so on.<\/p>\n\n\n\n<p>To retrieve the distinct cities and states of customers, you can use the <code>SELECT DISTINCT<\/code> with the <code>city<\/code> and <code>state<\/code> columns:<\/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\"><span class=\"hljs-keyword\">SELECT<\/span> \n  <span class=\"hljs-keyword\">DISTINCT<\/span> city, state \n<span class=\"hljs-keyword\">FROM<\/span> \n  sales.customers<\/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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"136\" height=\"169\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-SELECT-DISTINCT-multiple-columns-example.png\" alt=\"SQL Server SELECT DISTINCT - multiple columns example\" class=\"wp-image-193\"\/><\/figure>\n\n\n\n<p>In this example, the statement uses the combination of values in both <code>city<\/code> and <code>state<\/code> columns to evaluate the duplicate.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='3-using-select-distinct-with-null'>3) Using SELECT DISTINCT with NULL <a href=\"#3-using-select-distinct-with-null\" class=\"anchor\" id=\"3-using-select-distinct-with-null\" title=\"Anchor for 3) Using SELECT DISTINCT with NULL\">#<\/a><\/h3>\n\n\n\n<p>The following statement finds the distinct phone numbers of customers:<\/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\"><span class=\"hljs-keyword\">SELECT<\/span> \n  <span class=\"hljs-keyword\">DISTINCT<\/span> phone \n<span class=\"hljs-keyword\">FROM<\/span> \n  sales.customers \n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> \n  phone;<\/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<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"91\" height=\"169\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-SELECT-DISTINCT-null-example.png\" alt=\"SQL Server SELECT DISTINCT - null example\" class=\"wp-image-194\"\/><\/figure>\n\n\n\n<p>In this example, the <code>DISTINCT<\/code> clause keeps only one NULL in the <code>phone<\/code> column&nbsp;and removes other NULLs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='distinct-vs-group-by'>DISTINCT vs. GROUP BY <a href=\"#distinct-vs-group-by\" class=\"anchor\" id=\"distinct-vs-group-by\" title=\"Anchor for DISTINCT vs. GROUP BY\">#<\/a><\/h2>\n\n\n\n<p>The following statement uses the <code>GROUP BY<\/code> clause to return distinct cities together with state and zip code from the <code>sales.customers<\/code> table:<\/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  city, \n  state, \n  zip_code \n<span class=\"hljs-keyword\">FROM<\/span> \n  sales.customers \n<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span> \n  city, \n  state, \n  zip_code \n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> \n  city, \n  state, \n  zip_code<\/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 partial output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"177\" height=\"262\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-SELECT-DISTINCT-vs-GROUP-BY.png\" alt=\"SQL Server SELECT DISTINCT vs GROUP BY\" class=\"wp-image-1997\"\/><\/figure>\n\n\n\n<p>It is equivalent to the following query that uses the <code>DISTINCT<\/code> operator :<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" 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  <span class=\"hljs-keyword\">DISTINCT<\/span> city, state, zip_code \n<span class=\"hljs-keyword\">FROM<\/span> \n  sales.customers;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><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>Both <code>DISTINCT<\/code> and <code>GROUP BY<\/code> clause reduces the number of returned rows in the result set by removing the duplicates.<\/p>\n\n\n\n<p>However, you should use the <code>GROUP BY<\/code> clause when you want to apply an <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-aggregate-functions\/\">aggregate function<\/a> to one or more columns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the SQL Server <code>SELECT DISTINCT<\/code> clause to retrieve the distinct values from one or more columns.<\/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=\"176\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/\"\n\t\t\t\tdata-post-title=\"SQL Server SELECT DISTINCT\"\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=\"176\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/\"\n\t\t\t\tdata-post-title=\"SQL Server SELECT DISTINCT\"\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 Server SELECT DISTINCT clause to retrieve the only distinct values in a specified list of columns.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":100,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-176","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>SQL Server SELECT DISTINCT<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the SQL Server SELECT DISTINCT clause to retrieve the only distinct values in a specified list of columns.\" \/>\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.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server SELECT DISTINCT\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the SQL Server SELECT DISTINCT clause to retrieve the only distinct values in a specified list of columns.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-24T14:05:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/customers.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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-select-distinct\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-select-distinct\\\/\",\"name\":\"SQL Server SELECT DISTINCT\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-select-distinct\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-select-distinct\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/customers.png\",\"datePublished\":\"2018-04-13T04:39:50+00:00\",\"dateModified\":\"2024-09-24T14:05:31+00:00\",\"description\":\"This tutorial shows you how to use the SQL Server SELECT DISTINCT clause to retrieve the only distinct values in a specified list of columns.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-select-distinct\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-select-distinct\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-select-distinct\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/customers.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/customers.png\",\"width\":181,\"height\":231,\"caption\":\"customers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/sql-server-select-distinct\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Basics\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-basics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Server SELECT DISTINCT\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\",\"name\":\"SQL Server Tutorial\",\"description\":\"The Practical SQL Server Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/?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 Server SELECT DISTINCT","description":"This tutorial shows you how to use the SQL Server SELECT DISTINCT clause to retrieve the only distinct values in a specified list of columns.","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.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server SELECT DISTINCT","og_description":"This tutorial shows you how to use the SQL Server SELECT DISTINCT clause to retrieve the only distinct values in a specified list of columns.","og_url":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2024-09-24T14:05:31+00:00","og_image":[{"url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/customers.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/","url":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/","name":"SQL Server SELECT DISTINCT","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/customers.png","datePublished":"2018-04-13T04:39:50+00:00","dateModified":"2024-09-24T14:05:31+00:00","description":"This tutorial shows you how to use the SQL Server SELECT DISTINCT clause to retrieve the only distinct values in a specified list of columns.","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/#primaryimage","url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/customers.png","contentUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/customers.png","width":181,"height":231,"caption":"customers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-select-distinct\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"SQL Server Basics","item":"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/"},{"@type":"ListItem","position":3,"name":"SQL Server SELECT DISTINCT"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlservertutorial.net\/#website","url":"https:\/\/www.sqlservertutorial.net\/","name":"SQL Server Tutorial","description":"The Practical SQL Server Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlservertutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/comments?post=176"}],"version-history":[{"count":4,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/176\/revisions"}],"predecessor-version":[{"id":4576,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/176\/revisions\/4576"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/100"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}