{"id":18649,"date":"2022-11-08T05:59:00","date_gmt":"2022-11-08T04:59:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=18649"},"modified":"2023-03-02T14:58:56","modified_gmt":"2023-03-02T13:58:56","slug":"sql-server-select-queries-to-filter-data","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/","title":{"rendered":"SQL Server SELECT query examples to display and filter data from tables"},"content":{"rendered":"\n<h4 class=\"has-text-align-center wp-block-heading\" id=\"h-example-queries-with-the-sql-server-select-function-to-select-filter-and-display-data\"><strong><em>Example queries with the SQL Server SELECT function to select, filter and display data.<\/em><\/strong><\/h4>\n\n\n\n<p>This tutorial offers an extensive collection of SQL Server SELECT query examples to display and filter data from tables. The SELECT query is a powerful and versatile command that allows you to extract and manipulate data with precision and ease. By mastering its usage, you can enhance your Structured Query <a href=\"https:\/\/www.techopedia.com\/definition\/1245\/structured-query-language-sql\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Langage<\/a> skills and improve your data querying efficiency.<\/p>\n\n\n\n<p>This tutorial includes various examples that demonstrate how to select single and multiple columns, use aliases and column headings, filter data with the WHERE clause, use aggregation functions with GROUP BY, and filter grouped data with the HAVING clause. Whether you are new to SQL or a seasoned professional, this tutorial provides a valuable resource to enhance your SELECT statement expertise and its applications in SQL Server.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#1-prepare-the-data-to-query-using-the-sql-server-select\" >1. Prepare the data to query using the SQL Server Select<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#2-single-column-query-using-select\" >2. Single column query using Select<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#3-select-star-from-type-query-to-display-all-columns\" >3. Select Star From type query to display all columns<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#4-using-aliases-in-sql-server-select\" >4. Using aliases in SQL Server Select<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#5-rename-a-column-in-a-ms-sql-select-clause\" >5. Rename a column in a MS SQL SELECT clause<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#6-sql-server-select-using-the-where-clause-to-filter-data\" >6. SQL Server SELECT using the WHERE clause to filter data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#7-using-select-with-column-headings-and-calculations\" >7. Using SELECT with column headings and calculations<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#8-using-distinct-with-select-and-order-by\" >8. Using DISTINCT with SELECT and Order By<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#9-using-group-by-in-a-select-query\" >9. Using GROUP BY in a select query<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#10-using-group-by-with-multiple-groups\" >10. Using GROUP BY with multiple groups<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#11-using-group-by-and-where\" >11. Using GROUP BY and WHERE<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#12-using-group-by-with-an-expression\" >12. Using GROUP BY with an expression<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#13-using-group-by-with-order-by\" >13. Using GROUP BY with ORDER BY<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#14-using-the-having-clause-in-a-sql-select-statement\" >14. Using the HAVING clause in a SQL Select statement<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#conclusion-on-the-sql-server-select-statement\" >Conclusion on the SQL Server Select statement<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1-prepare-the-data-to-query-using-the-sql-server-select\"><\/span>1. Prepare the data to query using the SQL Server Select<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 Create the table used in the SELECT queries<\/h3>\n\n\n\n<p>First, before running the selection commands, create the example table of sales by month with this script.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Test if the table already exists\n-- If it doaes then delete the table\nIF EXISTS(\n   SELECT 1 FROM sys.objects\n   WHERE object_id = object_id(N'[dbo].[SALES]')\n      AND type in (N'U')\n)\nDROP TABLE [dbo].[Sales]\nGO\n\n-- Create the example table to store SALES\nCREATE TABLE [dbo].[Sales] (\n   [MonthName] nvarchar(20),\n   [Amount] numeric(8)\n)\nGO\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 Insert sample data to query into the sales table<\/h3>\n\n\n\n<p>Second step, insert rows with monthly sales amounts for the 12 months of the year.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Inserting the Sales data for our example\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'January', 1000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'February', 2000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'March', 3000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'April', 1000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'May', 2000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'June', 3000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'July', 1000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'August', 2000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'September', 3000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'October', 1000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'November', 2000);\nINSERT INTO dbo.SALES ([MonthName], Amount) VALUES (N'December', 3000);\nGO\n\n-- Select results for checking\nSELECT *\nFROM dbo.SALES;\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2-single-column-query-using-select\"><\/span>2. Single column query using Select<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the example below, select only the MONTH column from the sales table.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT [MonthName]\nFROM   dbo.SALES;\n<\/pre>\n\n\n\n<p>Here is a screenshot of the SQL Server Select example query to display only the month from the sales table, created in the section above.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"480\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sql-server-select-queries-1-one-column.jpg\" alt=\"SQL Server SELECT query examples to display one column from the table using SSMS\" class=\"wp-image-18660\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sql-server-select-queries-1-one-column.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sql-server-select-queries-1-one-column-300x200.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\"><strong><em>SQL Server SELECT query examples to display one column from the table using SSMS<\/em><\/strong><\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3-select-star-from-type-query-to-display-all-columns\"><\/span>3. Select Star From type query to display all columns<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>On the other hand, in this example, the query displays all the columns of the table, i.e. MONTH and AMOUNT.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT *\nFROM   dbo.SALES;\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"480\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sql-server-select-queries-2-all-columns.jpg\" alt=\"SQL Server SELECT query examples to display all the columns from the table\" class=\"wp-image-18669\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sql-server-select-queries-2-all-columns.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sql-server-select-queries-2-all-columns-300x200.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\"><strong><strong><em>SQL Server SELECT query examples to display all the columns from the table<\/em><\/strong><\/strong><\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4-using-aliases-in-sql-server-select\"><\/span>4. Using aliases in SQL Server Select<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Return all rows and columns from the <code>Sales<\/code> table, using table aliasing:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT s.*  \nFROM dbo.Sales AS s  \nORDER BY MonthName;  \n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5-rename-a-column-in-a-ms-sql-select-clause\"><\/span>5. Rename a column in a MS SQL SELECT clause<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Return all rows and a subset of columns from the <code>Sales<\/code> table, with a renamed column. Here it is the Amount column that is renamed as <em>TotalAmount<\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT MonthName, Amount AS TotalAmount  \nFROM dbo.Sales  \nOR<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6-sql-server-select-using-the-where-clause-to-filter-data\"><\/span>6. SQL Server SELECT using the WHERE clause to filter data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The WHERE clause allows you to filter the data by adding one or more conditions and thus display only the rows of the table that match the condition. The WHERE clause in SQL is certainly the most used LMD clause in the database field. LMD stands for Data Manipulation Language, which is the language used to manipulate data and not the objects themselves.<\/p>\n\n\n\n<p>Data filtering in SQL Server can be done in two ways:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Horizontal filtering<\/li>\n\n\n\n<li>Vertical filtering<\/li>\n<\/ol>\n\n\n\n<p>Horizontal <a href=\"https:\/\/help.libreoffice.org\/latest\/lo\/text\/scalc\/guide\/database_filter.html\" target=\"_blank\" rel=\"noreferrer noopener\">filtering<\/a> involves selecting one or more columns from a table. This allows you to limit the data returned to only the columns you are interested in, which can be useful for performance and readability.<\/p>\n\n\n\n<p>Vertical filtering, on the other hand, involves filtering the data based on specific conditions using the WHERE clause. This allows you to retrieve only the rows that meet certain criteria, such as a specific date range, a particular customer, or any other condition you specify.<\/p>\n\n\n\n<p>For example, if you have a table of sales data with columns for date, product, and amount, you could use horizontal filtering to select only the date and amount columns, and vertical filtering to retrieve only the rows where the amount is greater than a certain value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.1 Selection with a filter on the Month column<\/h3>\n\n\n\n<p>To display the month name and amount of the row whose month name is exactly January.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT\n  [MonthName],\n  [Amount]\nFROM  dbo.SALES\nWHERE [MonthName] = 'January';<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6.2 Selection query with the WHERE clause and an OR operator<\/h3>\n\n\n\n<p>The OR operator is a logical OR. To display the months whose name is January or February. Note that the OR clause allows you to mix conditions on different columns and thus filter the data in the table precisely. Either in an inclusive or more exclusive way.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT\n  [MonthName],\n  [Amount]\nFROM  dbo.SALES\nWHERE [MonthName] = 'January'\n  OR  [MonthName] = 'February'\n  OR  [Amount] > 1000;\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"480\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sql-server-select-queries-3-filter-or-clause.jpg\" alt=\"SQL Server SELECT query examples to display specific data using the OR operator as a filter\" class=\"wp-image-18677\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sql-server-select-queries-3-filter-or-clause.jpg 720w, https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/sql-server-select-queries-3-filter-or-clause-300x200.jpg 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\"><strong><strong><strong><em>SQL Server SELECT query examples to display specific data using the OR operator as a filter<\/em><\/strong><\/strong><\/strong><\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">6.3 MS SQL selection query with the IN operator<\/h3>\n\n\n\n<p>Similarly, to display all the rows in the table whose month is equal to a specific value, use the SQL IN operator. For example, this query will display the first three months of the year:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>January<\/li>\n\n\n\n<li>February<\/li>\n\n\n\n<li>March<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT\n  [MonthName],\n  [Amount]\nFROM dbo.SALES\nWHERE [MonthName] IN ('January', 'February', 'March');<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6.4 SQL query with WHERE clause and the different operator<\/h3>\n\n\n\n<p>To display a list of all customers whose name is different from MAMMADOU. This example query uses the star keyword: *. The SLECT * keyword displays all the columns of the table. The SELECT star keyword, also called SELECT STAR in English, or allows to display all the columns without naming them explicitly.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT *\nFROM dbo.SALES\nWHERE [MonthName] &lt;> 'December';\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Good practices on using Select query and naming columns<\/h4>\n\n\n\n<p>Note that it is good SQL Server practice not to use the SELECT * keyword. Especially in programs or scripts where the columns change. Indeed, if a column name changes then the program no longer recognizes the column. Unless the program manages the column names dynamically. It is therefore recommended to name all columns explicitly to control :<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The exact number of columns used<\/li>\n\n\n\n<li>The name of the columns<\/li>\n\n\n\n<li>And the order of the columns<\/li>\n\n\n\n<li><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7-using-select-with-column-headings-and-calculations\"><\/span>7. Using SELECT with column headings and calculations<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The seventh example presented below returns all rows from the Sales table, and calculate the total amount for each month.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT MonthName, Amount, Amount * 12 AS TotalAmount  \nFROM dbo.Sales  \nORDER BY MonthName;  \n<\/pre>\n\n\n\n<p>This query selects all rows from the <code>Sales<\/code> table and calculates the total amount for each month by multiplying the <code>Amount<\/code> column by 12 and assigning the result to the <code>TotalAmount<\/code> column. The results are sorted by <code>MonthName<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8-using-distinct-with-select-and-order-by\"><\/span>8. Using DISTINCT with SELECT and Order By<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Return a list of all unique month names in the Sales table. The script below selects only the unique <code>MonthName<\/code> values from the <code>Sales<\/code> table and sorts them in ascending order.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT DISTINCT MonthName  \nFROM dbo.Sales  \nORDER BY MonthName;  \n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"9-using-group-by-in-a-select-query\"><\/span>9. Using GROUP BY in a select query<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Generally the GROUP BY is combined with aggregation functions, like SUM, AVG, MIN or MAX. For example, to find the total amount for all sales:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT SUM(Amount) AS TotalSales  \nFROM dbo.Sales;  \n<\/pre>\n\n\n\n<p>This query calculates the sum of the <code>Amount<\/code> column for all rows in the <code>Sales<\/code> table and returns it as a single row with the column name <code>TotalSales<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"10-using-group-by-with-multiple-groups\"><\/span>10. Using GROUP BY with multiple groups<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This T-SQL query calculates the average and total sales for each unique <code>MonthName<\/code> value contained in the <code>Sales<\/code> table. The results are sorted by <code>MonthName<\/code>. To to find the average and total sales for each month, copy, paste and <a href=\"https:\/\/expert-only.com\/en\/ssms\/download-ssms-18\/\">execute this query in SSMS<\/a> for example.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT MonthName, AVG(Amount) AS AvgSales, SUM(Amount) AS TotalSales  \nFROM dbo.Sales  \nGROUP BY MonthName  \nORDER BY MonthName;  \n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"11-using-group-by-and-where\"><\/span>11. Using GROUP BY and WHERE<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Find the total sales for each month, but only for the months with sales greater than 2000. Indeed, this GROUP BY query calculates the total sales for each unique <code>MonthName<\/code> value in the <code>Sales<\/code> table. But only for the months where the <code>Amount<\/code> is greater than 2000. The results are sorted by <code>MonthName<\/code>. By default, the sort order is ascendant, i.e. equivalent to ASC.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT MonthName, SUM(Amount) AS TotalSales  \nFROM dbo.Sales  \nWHERE Amount > 2000  \nGROUP BY MonthName  \nORDER BY MonthName;  \n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"12-using-group-by-with-an-expression\"><\/span>12. Using GROUP BY with an expression<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Group the sales by the first letter of the month name. This query groups the sales from the sample <a href=\"https:\/\/expert-only.com\/en\/t-sql\/display-month-name-sql-server\/\">by the first three letters of the <code>MonthName<\/code> value<\/a> using the <code>LEFT<\/code> function. The results are sorted by <code>Month<\/code>Abbreviation. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT LEFT(MonthName, 3) AS MonthAbbreviation, SUM(Amount) AS TotalSales  \nFROM dbo.Sales  \nGROUP BY LEFT(MonthName, 1)  \nORDER BY MonthAbbreviation;  \n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"13-using-group-by-with-order-by\"><\/span>13. Using GROUP BY with ORDER BY<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Find the total sales for each month, and order the results by the amount in descending order.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT MonthName, SUM(Amount) AS TotalSales  \nFROM dbo.Sales  \nGROUP BY MonthName  \nORDER BY TotalSales DESC;  \n<\/pre>\n\n\n\n<p>This second-to-last query calculates the total sales for each unique <code>MonthName<\/code> value in the <code>Sales<\/code> table and orders the results by the <code>TotalSales<\/code> column in descending order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"14-using-the-having-clause-in-a-sql-select-statement\"><\/span>14. Using the HAVING clause in a SQL Select statement<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This last query finds the total sales for each month but only for the months with total sales greater than 4000, using the HAVING clause. The HAVING clause allows you to filter the results of a GROUP BY query based on aggregate values.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT MonthName, SUM(Amount) AS TotalSales  \nFROM dbo.Sales  \nGROUP BY MonthName  \nHAVING SUM(Amount) > 2000  \nORDER BY MonthName;\n<\/pre>\n\n\n\n<p>Explanation of the code, step by step:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The <code>SELECT<\/code> statement retrieves the <code>MonthName<\/code> column and the sum of the <code>Amount<\/code> column, aliased as <code>TotalSales<\/code>.<\/li>\n\n\n\n<li>The <code>FROM<\/code> clause specifies the <code>dbo.Sales<\/code> table.<\/li>\n\n\n\n<li>The <code>GROUP BY<\/code> clause groups the rows by <code>MonthName<\/code>.<\/li>\n\n\n\n<li>The <code>HAVING<\/code> clause filters the groups by the sum of the <code>Amount<\/code> column, selecting only those groups with a sum greater than 4000.<\/li>\n\n\n\n<li>The <code>ORDER BY<\/code> clause sorts the results by <code>MonthName<\/code>.<\/li>\n<\/ol>\n\n\n\n<p>The result will display the month names and the total sales for each month, but only for the months with total sales greater than 4000. The output gives something like this, if using the sample sales data.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>MonthName<\/th><th>TotalSales<\/th><\/tr><\/thead><tbody><tr><td>March<\/td><td>3000<\/td><\/tr><tr><td>June<\/td><td>3000<\/td><\/tr><tr><td>September<\/td><td>3000<\/td><\/tr><tr><td>December<\/td><td>3000<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"conclusion-on-the-sql-server-select-statement\"><\/span>Conclusion on the SQL Server Select statement<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In conclusion, this tutorial provides a comprehensive overview of SQL Server SELECT query examples for selecting, filtering, and displaying data from tables. The SELECT query is the most widely used and indispensable query in SQL, and this tutorial covers various aspects of its usage, including selecting single and multiple columns, using aliases and column headings, filtering data with the WHERE clause, using aggregation functions with GROUP BY, and filtering grouped data with the HAVING clause.<\/p>\n\n\n\n<p>By following the examples and explanations provided in this tutorial, you can gain a solid understanding of how to use the SQL Server SELECT query to extract and manipulate data from tables. Whether you are a beginner or an experienced SQL user, this tutorial is a valuable resource for mastering the SELECT statement and its applications in SQL Server.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"CNlnUjB4Wj\"><a href=\"https:\/\/expert-only.com\/en\/t-sql\/create-table-sql-server\/\">CREATE TABLE with SQL Server<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;CREATE TABLE with SQL Server&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/t-sql\/create-table-sql-server\/embed\/#?secret=jpWWdq2wHk#?secret=CNlnUjB4Wj\" data-secret=\"CNlnUjB4Wj\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">More T-SQL tutorials on how to manage tables<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-alter-table\/\">How to change a SQL Server table structure with ALTER TABLE?<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-insert-into-from-a-select\/\">Tutorial on the SQL Server insert into from a select statement.<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/expert-only.com\/en\/t-sql\/check-if-table-exists-in-sql-server\/\">Hoe to check if a table exists in SQL Server?<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Example queries with the SQL Server SELECT function to select, filter and display data. This tutorial offers an extensive collection of SQL Server SELECT query examples to display and filter data from tables. The SELECT query is a powerful <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/\" title=\"SQL Server SELECT query examples to display and filter data from tables\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":10609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-18649","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Server SELECT query examples to display and filter data<\/title>\n<meta name=\"description\" content=\"SQL Server SELECT query examples to display and filter data in SSMS, using the WHERE, clause and the IN, OR and DIFFERENT operators.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server SELECT query examples to display and filter data from tables\" \/>\n<meta property=\"og:description\" content=\"SQL Server SELECT query examples to display and filter data in SSMS, using the WHERE, clause and the IN, OR and DIFFERENT operators.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-08T04:59:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-02T13:58:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/desk-notes-pen-A4C6B252209_1920x1080.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"SQL Server SELECT query examples to display and filter data from tables\",\"datePublished\":\"2022-11-08T04:59:00+00:00\",\"dateModified\":\"2023-03-02T13:58:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/\"},\"wordCount\":1553,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/desk-notes-pen-A4C6B252209_1920x1080.jpg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/\",\"name\":\"SQL Server SELECT query examples to display and filter data\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/desk-notes-pen-A4C6B252209_1920x1080.jpg\",\"datePublished\":\"2022-11-08T04:59:00+00:00\",\"dateModified\":\"2023-03-02T13:58:56+00:00\",\"description\":\"SQL Server SELECT query examples to display and filter data in SSMS, using the WHERE, clause and the IN, OR and DIFFERENT operators.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/desk-notes-pen-A4C6B252209_1920x1080.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/desk-notes-pen-A4C6B252209_1920x1080.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server SELECT query examples to display and filter data from tables\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Server SELECT query examples to display and filter data","description":"SQL Server SELECT query examples to display and filter data in SSMS, using the WHERE, clause and the IN, OR and DIFFERENT operators.","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:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server SELECT query examples to display and filter data from tables","og_description":"SQL Server SELECT query examples to display and filter data in SSMS, using the WHERE, clause and the IN, OR and DIFFERENT operators.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2022-11-08T04:59:00+00:00","article_modified_time":"2023-03-02T13:58:56+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/desk-notes-pen-A4C6B252209_1920x1080.jpg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"SQL Server SELECT query examples to display and filter data from tables","datePublished":"2022-11-08T04:59:00+00:00","dateModified":"2023-03-02T13:58:56+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/"},"wordCount":1553,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/desk-notes-pen-A4C6B252209_1920x1080.jpg","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/","url":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/","name":"SQL Server SELECT query examples to display and filter data","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/desk-notes-pen-A4C6B252209_1920x1080.jpg","datePublished":"2022-11-08T04:59:00+00:00","dateModified":"2023-03-02T13:58:56+00:00","description":"SQL Server SELECT query examples to display and filter data in SSMS, using the WHERE, clause and the IN, OR and DIFFERENT operators.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/desk-notes-pen-A4C6B252209_1920x1080.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/desk-notes-pen-A4C6B252209_1920x1080.jpg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-select-queries-to-filter-data\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"SQL Server SELECT query examples to display and filter data from tables"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/18649","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=18649"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/18649\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/10609"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=18649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=18649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=18649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}