{"id":369,"date":"2023-01-08T07:15:59","date_gmt":"2023-01-08T07:15:59","guid":{"rendered":"https:\/\/jassweb.com\/new22\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed\/"},"modified":"2023-01-08T07:15:59","modified_gmt":"2023-01-08T07:15:59","slug":"solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/","title":{"rendered":"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed]"},"content":{"rendered":"<h2> Introduction <\/h2>\n<p>[ad_1]<\/p>\n<p>SQL is a powerful language used to query and manipulate data stored in databases. It is important to understand the syntax and structure of SQL queries in order to ensure that the query is valid and produces the desired results. One common issue that can arise when writing SQL queries is the error &#8220;Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause&#8221;. This error occurs when a column is included in the SELECT clause of a query, but is not included in either an aggregate function or the GROUP BY clause. This article will explain the cause of this error and provide solutions for resolving it.<\/p>\n<h2> Solution<\/h2>\n<p><\/p>\n<p>SELECT<br \/>\n    col1,<br \/>\n    col2,<br \/>\n    SUM(col3)<br \/>\nFROM<br \/>\n    table<br \/>\nGROUP BY<br \/>\n    col1, col2; <\/p>\n<p><\/p>\n<div class=\"entry-content\" itemprop=\"text\">\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-1088640234840270\" crossorigin=\"anonymous\"><\/script><br \/>\n<script><\/p>\n<p><\/script><\/p>\n<p>SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed]<\/p>\n<p>solved SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed] <\/p>\n<p><script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-1088640234840270\" crossorigin=\"anonymous\"><\/script><br \/>\n<script><\/p>\n<p><\/script><\/div>\n<p>[ad_2]<\/p>\n<p>When writing a SQL query, it is important to remember that any column used in the SELECT clause must either be included in an aggregate function or in the GROUP BY clause. If a column is not included in either of these, the query will return an error stating that the column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. <\/p>\n<p>To resolve this issue, the column must be included in either an aggregate function or the GROUP BY clause. An aggregate function is a function that performs a calculation on a set of values and returns a single value. Examples of aggregate functions include COUNT, SUM, AVG, MIN, and MAX. The GROUP BY clause is used to group the results of a query by one or more columns. <\/p>\n<p>For example, if we wanted to find the total number of orders for each customer, we could write the following query:<\/p>\n<pre>SELECT customer_id, COUNT(*) AS total_orders\nFROM orders\nGROUP BY customer_id<\/pre>\n<p>In this query, the customer_id column is included in the GROUP BY clause, so the query will execute without any errors. <\/p>\n<p>In summary, when writing a SQL query, it is important to remember that any column used in the SELECT clause must either be included in an aggregate function or in the GROUP BY clause. If a column is not included in either of these, the query will return an error stating that the column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. To resolve this issue, the column must be included in either an aggregate function or the GROUP BY clause.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction [ad_1] SQL is a powerful language used to query and manipulate data stored in databases. It is important to understand the syntax and structure of SQL queries in order to ensure that the query is valid and produces the desired results. One common issue that can arise when writing SQL queries is the error &#8230; <a title=\"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/\" aria-label=\"More on [Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[341,500,501],"class_list":["post-369","post","type-post","status-publish","format-standard","hentry","category-solved","tag-sql","tag-sql-server","tag-sql-server-2008"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"Introduction [ad_1] SQL is a powerful language used to query and manipulate data stored in databases. It is important to understand the syntax and structure of SQL queries in order to ensure that the query is valid and produces the desired results. One common issue that can arise when writing SQL queries is the error ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-08T07:15:59+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed]\",\"datePublished\":\"2023-01-08T07:15:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/\"},\"wordCount\":482,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"sql\",\"sql-server\",\"sql-server-2008\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/\",\"name\":\"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2023-01-08T07:15:59+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed] - JassWeb","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:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed] - JassWeb","og_description":"Introduction [ad_1] SQL is a powerful language used to query and manipulate data stored in databases. It is important to understand the syntax and structure of SQL queries in order to ensure that the query is valid and produces the desired results. One common issue that can arise when writing SQL queries is the error ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/","og_site_name":"JassWeb","article_published_time":"2023-01-08T07:15:59+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed]","datePublished":"2023-01-08T07:15:59+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/"},"wordCount":482,"commentCount":0,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["sql","sql-server","sql-server-2008"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/","url":"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/","name":"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-01-08T07:15:59+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-sql-column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggregate-function-or-the-group-by-clause-closed-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] SQL: Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=369"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/369\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}