<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bigland Network</title>
    <description>The latest articles on DEV Community by Bigland Network (@biglandnetwork).</description>
    <link>https://dev.to/biglandnetwork</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4279329%2Fff77f82f-32d3-4a06-974a-42487b526aff.png</url>
      <title>DEV Community: Bigland Network</title>
      <link>https://dev.to/biglandnetwork</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/biglandnetwork"/>
    <language>en</language>
    <item>
      <title>SQL Server for Beginners: SELECT, WHERE and ORDER BY Explained with Examples</title>
      <dc:creator>Bigland Network</dc:creator>
      <pubDate>Wed, 02 Dec 2026 22:58:36 +0000</pubDate>
      <link>https://dev.to/biglandnetwork/sql-server-for-beginners-select-where-and-order-by-explained-with-examples-29fg</link>
      <guid>https://dev.to/biglandnetwork/sql-server-for-beginners-select-where-and-order-by-explained-with-examples-29fg</guid>
      <description>&lt;p&gt;&lt;em&gt;This tutorial was originally published on &lt;a href="https://biglandnetwork.com/sql-server-select-where-order-by-beginners/" rel="noopener noreferrer"&gt;biglandnetwork.com&lt;/a&gt;. It is part of the free &lt;strong&gt;SQL Server for Beginners&lt;/strong&gt; series, with a 10-minute video for every lesson.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/PSoLHL9DJPA" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you are new to databases, the first skill to learn is how to &lt;strong&gt;read data&lt;/strong&gt;. In SQL Server that means three clauses: &lt;code&gt;SELECT&lt;/code&gt; to choose columns, &lt;code&gt;WHERE&lt;/code&gt; to filter rows and &lt;code&gt;ORDER BY&lt;/code&gt; to sort. With only these you can already answer many real questions. This guide builds them step by step on a tiny table, and every result is shown so you can check your own.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Part of the SQL Server for Beginners series.&lt;/strong&gt; This article is the written version of lesson 1 of the Bigland Network video course, with the same sample data. The results shown were worked out by hand from that data, so run every example on a test database, not on production data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  1. The table we will use
&lt;/h2&gt;

&lt;p&gt;A database stores data in &lt;strong&gt;tables&lt;/strong&gt;. A table has &lt;strong&gt;columns&lt;/strong&gt; (the kinds of information) and &lt;strong&gt;rows&lt;/strong&gt; (one record each). In this lesson we use a small table called &lt;code&gt;Employees&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Id&lt;/th&gt;
&lt;th&gt;FirstName&lt;/th&gt;
&lt;th&gt;Department&lt;/th&gt;
&lt;th&gt;Salary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Amina&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;td&gt;4200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Youssef&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;td&gt;5200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Salma&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;td&gt;3600&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Karim&lt;/td&gt;
&lt;td&gt;HR&lt;/td&gt;
&lt;td&gt;3100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Nadia&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;td&gt;4800&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To follow along, create the table in a test database using SQL Server Management Studio (SSMS) or Azure Data Studio:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="nc"&gt;Employees&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;Id&lt;/span&gt;         &lt;span class="kt"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;FirstName&lt;/span&gt;  &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Department&lt;/span&gt; &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Salary&lt;/span&gt;     &lt;span class="kt"&gt;INT&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="nc"&gt;Employees&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt;
 &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'Amina'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'Sales'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'Youssef'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'IT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'Salma'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'Sales'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'Karim'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'HR'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'Nadia'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'IT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4800&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. SELECT: read data
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;SELECT&lt;/code&gt; chooses what to show and &lt;code&gt;FROM&lt;/code&gt; says which table to read. The star means all columns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nc"&gt;Employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns the whole table. It is fine for exploring, but in real work you should name the columns you need. It is faster, clearer, and it keeps working if somebody adds a column later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nc"&gt;FirstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Department&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nc"&gt;Employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;FirstName&lt;/th&gt;
&lt;th&gt;Department&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Amina&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Youssef&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Salma&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Karim&lt;/td&gt;
&lt;td&gt;HR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nadia&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  3. WHERE: filter rows
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;WHERE&lt;/code&gt; keeps only the rows that match a condition. Text values go inside single quotes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nc"&gt;FirstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Department&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nc"&gt;Employees&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="nc"&gt;Department&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Sales'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;FirstName&lt;/th&gt;
&lt;th&gt;Department&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Amina&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Salma&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For numbers, use comparison operators: &lt;code&gt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; (not equal), &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;. Numbers do not need quotes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nc"&gt;FirstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Salary&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nc"&gt;Employees&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="nc"&gt;Salary&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;4000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;FirstName&lt;/th&gt;
&lt;th&gt;Salary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Amina&lt;/td&gt;
&lt;td&gt;4200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Youssef&lt;/td&gt;
&lt;td&gt;5200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nadia&lt;/td&gt;
&lt;td&gt;4800&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  4. Combine conditions with AND and OR
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;AND&lt;/code&gt; needs both conditions to be true. &lt;code&gt;OR&lt;/code&gt; needs at least one. When you mix them, add parentheses so the meaning is clear.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nc"&gt;FirstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Department&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Salary&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nc"&gt;Employees&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="nc"&gt;Department&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'IT'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="nc"&gt;Salary&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;FirstName&lt;/th&gt;
&lt;th&gt;Department&lt;/th&gt;
&lt;th&gt;Salary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Youssef&lt;/td&gt;
&lt;td&gt;IT&lt;/td&gt;
&lt;td&gt;5200&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nc"&gt;FirstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Department&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nc"&gt;Employees&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="nc"&gt;Department&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'HR'&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="nc"&gt;Department&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Sales'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;FirstName&lt;/th&gt;
&lt;th&gt;Department&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Amina&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Salma&lt;/td&gt;
&lt;td&gt;Sales&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Karim&lt;/td&gt;
&lt;td&gt;HR&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Other useful filters are &lt;code&gt;IN ('Sales','HR')&lt;/code&gt;, &lt;code&gt;BETWEEN 3000 AND 4000&lt;/code&gt; and &lt;code&gt;LIKE 'A%'&lt;/code&gt; (names that start with A).&lt;/p&gt;

&lt;h2&gt;
  
  
  5. ORDER BY: sort the results
&lt;/h2&gt;

&lt;p&gt;Without &lt;code&gt;ORDER BY&lt;/code&gt; SQL Server gives you no guaranteed order. Add it whenever the order matters. The default is ascending; add &lt;code&gt;DESC&lt;/code&gt; for highest first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nc"&gt;FirstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Salary&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nc"&gt;Employees&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="nc"&gt;Salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;FirstName&lt;/th&gt;
&lt;th&gt;Salary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Youssef&lt;/td&gt;
&lt;td&gt;5200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nadia&lt;/td&gt;
&lt;td&gt;4800&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Amina&lt;/td&gt;
&lt;td&gt;4200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Salma&lt;/td&gt;
&lt;td&gt;3600&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Karim&lt;/td&gt;
&lt;td&gt;3100&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  6. Putting it all together
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nc"&gt;FirstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Salary&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nc"&gt;Employees&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="nc"&gt;Department&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'IT'&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="nc"&gt;Salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;FirstName&lt;/th&gt;
&lt;th&gt;Salary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Youssef&lt;/td&gt;
&lt;td&gt;5200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nadia&lt;/td&gt;
&lt;td&gt;4800&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Always write the clauses in this order: &lt;code&gt;SELECT&lt;/code&gt;, &lt;code&gt;FROM&lt;/code&gt;, &lt;code&gt;WHERE&lt;/code&gt;, &lt;code&gt;ORDER BY&lt;/code&gt;. (SQL Server &lt;em&gt;reads&lt;/em&gt; them in a different order, which lesson 3 explains.)&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Forgetting the quotes around text: &lt;code&gt;WHERE Department = Sales&lt;/code&gt; makes SQL Server look for a column named Sales.&lt;/li&gt;
&lt;li&gt;Using double quotes for text. Use single quotes for values.&lt;/li&gt;
&lt;li&gt;Writing &lt;code&gt;= NULL&lt;/code&gt; to find empty values. Use &lt;code&gt;IS NULL&lt;/code&gt; instead (lesson 8 explains NULL).&lt;/li&gt;
&lt;li&gt;Relying on &lt;code&gt;SELECT *&lt;/code&gt; in applications and reports.&lt;/li&gt;
&lt;li&gt;Assuming a table comes back in a fixed order without &lt;code&gt;ORDER BY&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. Practice
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Show the names of the employees in HR.&lt;/li&gt;
&lt;li&gt;Show everyone who earns less than 4000, lowest salary first.&lt;/li&gt;
&lt;li&gt;Show Sales employees who earn more than 4000.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Answers: &lt;code&gt;SELECT FirstName FROM Employees WHERE Department = 'HR';&lt;/code&gt; returns Karim. &lt;code&gt;SELECT FirstName, Salary FROM Employees WHERE Salary &amp;lt; 4000 ORDER BY Salary;&lt;/code&gt; returns Karim (3100) then Salma (3600). The third returns Amina (4200).&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Do I need to install SQL Server to practise?
&lt;/h3&gt;

&lt;p&gt;Yes, or use a cloud database. The free Developer or Express edition of SQL Server plus SQL Server Management Studio (SSMS) or Azure Data Studio is enough for every lesson of this series.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is SQL case sensitive?
&lt;/h3&gt;

&lt;p&gt;Keywords such as SELECT and WHERE are not case sensitive. Text values depend on the database collation, and the default collation is usually case insensitive, so ‘sales’ matches ‘Sales’.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between SQL and T-SQL?
&lt;/h3&gt;

&lt;p&gt;SQL is the standard language. T-SQL (Transact-SQL) is the version used by SQL Server, with extra features such as variables, TRY…CATCH and TOP.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to learn next
&lt;/h2&gt;

&lt;p&gt;Next, learn how to combine several tables with JOINs in &lt;a href="https://biglandnetwork.com/sql-server-joins-explained-inner-left-right-full-cross-self/" rel="noopener noreferrer"&gt;Lesson 2: JOINs&lt;/a&gt;. For a quick reference of useful queries, see the &lt;a href="https://biglandnetwork.com/sql-server-dba-cheat-sheet-t-sql-queries/" rel="noopener noreferrer"&gt;SQL Server DBA Cheat Sheet&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The whole series
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://biglandnetwork.com/sql-server-select-where-order-by-beginners/" rel="noopener noreferrer"&gt;Lesson 1: SELECT, WHERE and ORDER BY&lt;/a&gt;&lt;/strong&gt; (this article)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-joins-explained-inner-left-right-full-cross-self/" rel="noopener noreferrer"&gt;Lesson 2: JOINs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-group-by-having-subqueries-beginners/" rel="noopener noreferrer"&gt;Lesson 3: GROUP BY, HAVING and Subqueries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-insert-update-delete-transactions-beginners/" rel="noopener noreferrer"&gt;Lesson 4: INSERT, UPDATE, DELETE and Transactions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-create-table-data-types-constraints-beginners/" rel="noopener noreferrer"&gt;Lesson 5: CREATE TABLE, Data Types and Constraints&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-indexes-views-stored-procedures-beginners/" rel="noopener noreferrer"&gt;Lesson 6: Indexes, Views and Stored Procedures&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-cte-window-functions-beginners/" rel="noopener noreferrer"&gt;Lesson 7: CTEs and Window Functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-built-in-functions-case-iif-coalesce-null/" rel="noopener noreferrer"&gt;Lesson 8: Built-in Functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-user-defined-functions-temp-tables-table-variables/" rel="noopener noreferrer"&gt;Lesson 9: Functions, Temp Tables and Table Variables&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-triggers-audit-tables-beginners/" rel="noopener noreferrer"&gt;Lesson 10: Triggers and Audit Tables&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-security-logins-users-roles-permissions-beginners/" rel="noopener noreferrer"&gt;Lesson 11: Security: Logins, Users and Roles&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-backup-restore-recovery-models-beginners/" rel="noopener noreferrer"&gt;Lesson 12: Backup, Restore and Recovery Models&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-query-performance-tuning-execution-plans-beginners/" rel="noopener noreferrer"&gt;Lesson 13: Query Performance Tuning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-agent-jobs-maintenance-schedules-alerts-beginners/" rel="noopener noreferrer"&gt;Lesson 14: SQL Server Agent Jobs and Maintenance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-encryption-auditing-hashbytes-masking-tde-beginners/" rel="noopener noreferrer"&gt;Lesson 15: Encryption and Auditing Basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-json-for-json-openjson-json-value-beginners/" rel="noopener noreferrer"&gt;Lesson 16: Working with JSON&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-temporal-tables-system-versioning-as-of-beginners/" rel="noopener noreferrer"&gt;Lesson 17: Temporal Tables and Row History&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-partitioning-large-tables-partition-function-scheme-switch-beginners/" rel="noopener noreferrer"&gt;Lesson 18: Partitioning and Large Tables&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-full-text-search-contains-freetext-beginners/" rel="noopener noreferrer"&gt;lesson 19: Full Text Search&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://biglandnetwork.com/sql-server-query-store-find-slow-queries-force-plan-beginners/" rel="noopener noreferrer"&gt;lesson 20: Query Store and Slow Queries&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Sources and further reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Microsoft Learn, &lt;em&gt;Transact-SQL reference (Database Engine)&lt;/em&gt;, on learn.microsoft.com: the official syntax for every statement used here.&lt;/li&gt;
&lt;li&gt;Microsoft Learn, &lt;em&gt;SQL Server documentation&lt;/em&gt;, for SQL Server Management Studio (SSMS) and the sample concepts.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Watch the video lesson on YouTube:&lt;/strong&gt; &lt;a href="https://www.youtube.com/watch?v=PSoLHL9DJPA" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=PSoLHL9DJPA&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read the original article (always up to date):&lt;/strong&gt; &lt;a href="https://biglandnetwork.com/sql-server-select-where-order-by-beginners/" rel="noopener noreferrer"&gt;https://biglandnetwork.com/sql-server-select-where-order-by-beginners/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;All the lessons:&lt;/strong&gt; &lt;a href="https://biglandnetwork.com/lessons/" rel="noopener noreferrer"&gt;https://biglandnetwork.com/lessons/&lt;/a&gt; · &lt;strong&gt;Subscribe on YouTube:&lt;/strong&gt; &lt;a href="https://www.youtube.com/@biglandnetwork" rel="noopener noreferrer"&gt;https://www.youtube.com/@biglandnetwork&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sql</category>
      <category>sqlserver</category>
      <category>database</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
