SQL – A Complete Guide for Beginners
Tags: sql, beginners, database
Published: 2022-03-10 12:15:25

---
title: SQL – A Complete Guide for Beginners
published: true
date: 2022-03-10 11:00:36 UTC
tags: sql, beginners, database
canonical_url: https://www.syncfusion.com/blogs/post/sql-a-complete-guide-for-beginners.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4agr8ksjzj02c0x4pau.png
---

Nowadays, every organization needs data to run its business. [Databases](https://en.wikipedia.org/wiki/Database "Wikipedia page for Database") are the best option to store organized collection of data.  And, [SQL (Structured Query Language)](https://en.wikipedia.org/wiki/SQL "Wikipedia page for SQL") is the most widely used programing language for organizing and retrieving the data in a database. It allows us to perform all the CRUD (create, read, update and delete) operations in the database.

In this article, we will discuss the basic concepts of SQL that every developer should know to effectively manage data in a database.

## Purpose of SQL

The main purpose of SQL is to operate and retrieve information from the relational database. It allows us to create new databases, views, tables, stored procedures, and functions.

## Prerequisite

- [Microsoft SQL Server Management Studio](https://aka.ms/ssmsfullsetup "Download Microsoft SQL Server Management Studio")

## Getting started

1. First, open the Microsoft SQL Server Management Studio.
2. Then, navigate to **File -> Connect Object Explorer.** Refer to the following image.  
 ![Connect Object Explorer in Microsoft SQL Server Management Studio](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/Connect-Object-Explorer-in-Microsoft-SQL-Server-Management-Studio.png)
3. Now, the **SQL Server** dialog box will appear. Your machine name will appear in the **Server Name** field. Make sure that  **Windows Authentication**  is chosen as the  **Authentication ** type. Then, select the **Connect** option.  
 ![Connect to Server Windows Authentication](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/Connect-to-Server-Windows-Authentication.png)A new window will appear, where you can execute the SQL queries explained in the following sections.

## Basics of SQL

We should have some knowledge of the following terms before we get started with SQL.

### Table

A table is a database object that presents data in columns and rows.

### Records and fields

Rows are described as records. The columns are described as fields that represent the category of the records. For example, a table of student details contains a row for each student and a column for each detail such as age, height, and so on.

## SQL data types

The basic things required to create a column are names and data types.  SQL supports the following three [data types](https://www.w3schools.com/sql/sql_datatypes.asp "SQL Data Types for MySQL, SQL Server, and MS Access"):

- String data type
- Numeric data type
- Date data type

## SQL clauses

SQL is a case-insensitive language. The major three clauses in SQL are **Select** , **from** , **where**.

### Select

Select is the most important clause in SQL. It helps us retrieve data from the table. Simply, it answers **What data should we show?**

### from

This retrieves data from a specific table in a database. Simply, it answers **Where do we get the data from?**

### where

This retrieves specific data records in a table. Simply, it answers  **Which category data should we show?**

**Syntax:**

```sql
Select * from <<Table Name>>  where <<Column Name>> = <<Value>>
```

**Example:**

![SQL Syntax Example](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/SQL-Syntax-Example.png)

## SQL categories

There are five categories in SQL:

- **Data definition language:** It performs **Create** , **Alter** , **Drop ** operations.
- **Data manipulation language:** It performs **Insert** , **Update** , **Delete ** operations.
- **Data control language** : It performs **Grant** and **Revoke ** operations.
- **Data query language:** It performs the  **Select ** operation.
- **Transaction control language:** It performs **Commit** and **Rollback** operations. ** **

## Commonly used keywords and their behavior in SQL

As a developer, we have to know the following commonly used keywords and their usage in SQL to get started with it:

### #1: CREATE

This keyword enables us to create a new table.

**Syntax:**

```sql
CREATE Table <<<<Table Name>>>>
(
   <<<< Column Name1>>>> datatype,
   <<<<Column Name2>>>> datatype
)
```

**Example:**  
 ![CREATE Keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/CREATE-Keyword.png)

**Output:**

![CREATE Keyword Output](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/CREATE-Keyword-Output.png)

### #2: Insert into

This keyword is used to insert new records (rows) in a table.

**Syntax:**

```sql
Insert into <<Table Name>>

Values (value1, value2, ….)
```

**Example:**  
 ![Insert into Keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Insert-into-Keyword.png)

**Output:**

![Insert into Keyword Output](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Insert-into-Keyword-Output.png)

Similarly, you can add multiple entries at a time like in the following image.

**Syntax:**

```sql
Insert into <<Table Name>>
Values (value1, value2, ….),
       (value1, value2, ….),
       (value1, value2, ….),
```

**Example:**

![Insert into Keyword Code Example](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Insert-into-Keyword-Code-Example.png) ** Output:**   ![Insert into Keyword Output](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Insert-into-Keyword-Output-1.png)

### #3: Update

Updates the existing records in a table.

**Syntax:**

```sql
Update <<<<Table Name>>>> set <<<<Column Name>>>> = <<<<value>>>> where <<<<Column Name>>>> = <<<<value>>>>
```

**Example:**

![Update Keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Update-Keyword.png) **Output:**

Before Update:

![Before Update](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Before-Update.png)

After Update:

![After Update](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/After-Update.png)

### #4: Distinct

This keyword removes duplicate records and gets the unique records from a table.

**Syntax:**

```sql
Select Distinct * from <<<<Table Name>>>>
```

**Example:**

![Distinct Keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Distinct-Keyword.png)Refer to the following image to retrieve particular distinct column values.

**Syntax:**

```sql
Select Distinct <<<<Column Name>>>> from <<<<Table Name>>>>
```

**Example:**

### ![Distinct Keyword Output](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Distinct-Keyword-Output.png) #5: top

Use this keyword to get the top values in a table.

**Syntax:**

```sql
Select top Numeric Value * from <<<<Table Name>>>>
```

**Example:**

![top keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/top-keyword.png)

### #6: order by

We can use this keyword to sort the records in ascending or descending order.

**Syntax:**

```sql
Select * from <<Table Name>> order by <<Column Name>> asc
```

To sort the records in ascending order, use the keyword **asc.**

**Example:**

![order by keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/order-by-keyword.png)To sort the records in descending order, use the Keyword **desc.**

** Syntax:**

```sql
Select * from <<<<Table Name>>>> order by <<<<Column Name>>>> desc
```

**Example:**

![Output of order by keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Output-of-order-by-keyword.png)

### #7: and

This keyword is used to display the records that satisfy all the conditions in the **where** clause.

**Syntax:**

```sql
Select * from <<Table Name>> where <<Column Name>> = <<Value>> and <<Column Name>> = <<Value>>

```

**Example:**  
 ![and keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/and-keyword.png)

### #8: or

This keyword displays the records that satisfy any one of the conditions in the **where** clause.

**Syntax:**

```sql
Select * from <<Table Name>> where <<Column Name>> = <<Value>> or <<Column Name>> = <<Value>>        

```

**Example:**

![or keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/or-keyword.png)

### #9: NOT

This keyword displays the records that don’t satisfy the provided condition.

**Syntax:**

```sql
Select * from <<Table Name>> where NOT <<Column Name>> = <<Value>>
```

**Example:**

![NOT keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/NOT-keyword.png)

### #10: MIN

This keyword displays the smallest value in a column.

**Syntax:**

```sql
Select MIN(<<<<Column Name>>>>) from <<<<Table Name>>>>
```

**Example:**

![MIN keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/MIN-keyword.png)

### #11: MAX

This keyword displays the largest value in a column.

**Syntax:**

```sql
Select MAX(<<<<Column Name>>>>) from <<<<Table Name>>>>
```

**Example:**

![MAX keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/MAX-keyword.png)

### #12: SUM

This keyword displays the total sum value for the numeric column.

**Syntax:**

```sql
Select SUM(<<Column Name>>) from <<Table Name>>
```

**Example:**

![SUM keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/SUM-keyword.png)

### #13: in

This keyword retrieves multiple values that satisfy the condition in the **where** clause.

** Syntax:**

```sql
Select * from <<Table Name>> where <<Column Name>> in (<<Value1>>, <<Value2>>, ….)
```

**Example:**

![in keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/in-keyword.png)

### #14: not in

This keyword retrieves multiple values that don’t satisfy the condition in the where clause.

** Syntax:**

```sql
Select * from <<Table Name>> where <<Column Name>> not in (<<Value1>>, <<Value2>>, ….)
```

**Example:**

![not in keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/not-in-keyword.png)

### #15: Count

Use the Count keyword to return the total number of rows in a table. We can use this to return the number of rows that satisfy the specified condition.

**Syntax:**

```sql
Select Count(*) from <<Table Name>>
```

**Example:**

![Count keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Count-keyword.png)

### #16: AVG

This keyword returns the average value of a column.

**Syntax:**

```sql
Select AVG(<<<<Column Name>>>>) from <<<<Table Name>>>>
```

**Example:**

![AVG keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/AVG-keyword.png)

### #17: ANY

This keyword is used to check whether the required records exist or not in a table.

**Syntax:**

```sql
Select * from <<Table Name>> where <<Column Name>> = ANY(Select * from <<Table Name>> where <<Column Name>> = <<Value>>)
```

**Example:**  
 ![ANY keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/ANY-keyword.png)

### #18: Like

This keyword retrieves a specified pattern in a column.

**Syntax:**

```sql
Select * from <<Table Name>> where <<Column Name>> Like ‘%Value%’
```

**Example:**

![Like keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Like-keyword.png)

### #19: UNION

This keyword is used to combine two or more select statements.

**Syntax:**

```sql
Select * from <<Table Name1>> 
UNION
Select * from <<Table Name2>>
```

**Example:**

![UNION keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/UNION-keyword.png)

### #20: Is NULL

This keyword retrieves the rows that satisfy the null value in a specific column.

**Syntax:**

```sql
Select * from <<Table Name>> where <<Column Name>> Is Null
```

**Example:**

![Is NULL keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Is-NULL-keyword.png)

### #21: IS NOT NULL

This keyword retrieves the rows that satisfy the not null value in a specific column.

**Syntax:**

```sql
Select * from <<Table Name>> where <<Column Name>> IS NOT NULL
```

**Example:**

![IS NOT NULL keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/IS-NOT-NULL-keyword.png)

### #22: WILDCARDS

This keyword is used instead of a particular character in a string to retrieve all possible values. Some common wildcard values in SQL are: \_ \* ? [] ! –

**Syntax:**

```sql
Select * from <<Table Name>> where <<Column Name>> LIKE ‘<<Value with WildCardValue>>’
```

**Example:**

![WILDCARDS](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/WILDCARDS.png)

### #23: GROUP BY

This keyword is used to group records. The main purpose of this statement is to find how many records have the same values in a table.

**Syntax:**

```sql
Select COUNT(<<<<Column name>>>>), <<<<Column Name>>>> from <<<<Table Name>>>> GROUP BY <<<<Column Name>>>>

```

**Example:**

![GROUP BY keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/GROUP-BY-keyword.png)

### #24: Aliases

We can give a temporary name for a column in the table. Here, the CustomerID column is named  **Id,** and the CustomerName column is named  **Name**.

**Syntax:**

```sql
Select <<<<Column Name>>>> as <<<<Temporary Name>>>> from <<<<Table Name>>>>
```

**Example:**  
 ![Aliases](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Aliases.png)

### #25: Between

This keyword retrieves the values within the given range.

**Syntax:**

```sql
Select * from <<<<Table Name>>>> where <<<<Column Name>>>> Between <<<<Value>>>> and <<<<Value>>>>
```

**Example:**

![Between keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Between-keyword.png)

### #26 Join

This keyword combines records from two or more tables using the common field in them. There are four types of join in SQL:

-   Inner Join
-   Left Join
-   Right Join
-   Full Join

Let’s look at these join keywords with example data.

**Table 1** : Students

**![Students](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/Students.png)Table 2:** StudentsMarkInformation

![StudentsMarkInformation](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/StudentsMarkInformation.png)

**Inner Join:**

The Inner Join returns the records that match the values in both tables. Inner Join is commonly referred to as just Join.

**Syntax:**

```sql
Select <<Column Name>>

From <<Table Name1>>

**Inner Join** <<Table Name2>> on <<Table Name1>>.<<Column Name>> = <<Table Name2>>.<<Column Name>>
```

**Example:**

![Inner Join keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/Inner-Join-keyword.png)

**Left Join:**

Left Join returns all the records from the left-side table and the matching records from the right-side table of the Join keyword.

**Syntax:**

```sql
Select <<Column Name>>

From <<Table Name1>>

**Left Join** <<Table Name2>> on <<Table Name1>>.<<Column Name>> = <<Table Name2>>.<<Column Name>>
```

**Example:**

![Left Join Keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/Left-Join-Keyword.png)

**Right Join:**

Right Join returns all the records from the right-side table and the matching records from the left-side table of the Join keyword.

**Syntax:**

```sql
Select <<Column Name>>

From <<Table Name1>>

**Right Join** <<Table Name2>> on <<Table Name1>>.<<Column Name>> = <<Table Name2>>.<<Column Name>>
```

**Example:**

![Right Join Keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/Right-Join-Keyword.png)

**Full Join:**

Full Join finds the matching records from both the Left Join and Right Join tables and returns all the records for comparision. If there is no match found, then it will return a NULL value for those records. It is also referred as Full Outer Join.

**Syntax:**

```sql
Select <<Column Name>>

From <<Table Name1>>

**Full Join** <<Table Name2>> on <<Table Name1>>.<<Column Name>> = <<Table Name2>>.<<Column Name>>
```

**Example:**

![Full Join Keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/Full-Join-Keyword.png)

### #26 Primary Key

Primary Key ensures that a value in a record is unique. It never contains NULL values.

**Syntax:**

```sql
Create Table <<Table Name>>

(

 <<Column Name1>> datatype Not Null **Primary Key** ,

 <<Column Name2>> datatype

)
```

**Example:** Here, the RollNo column is marked as Primary Key, as each student has a unique roll number.

![Primary Key Keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/Primary-Key-Keyword.png)

### #27 Foreign Key

Foreign Key is a field in one table that points to the primary key in another table.

**Syntax:**

```sql
Create Table <<Table Name>>

(

 <<Column Name1>> datatype Not Null Primary Key,

 <<Column Name2>> datatype **Foreign Key References** <<Existing Table Name>>(<<Existing Column Name>>),

 <<Column Name3>> datatype,

 <<Column Name4>> datatype

)
```

**Example:**

![Foreign Key Keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/Foreign-Key-Keyword.png)

### SQL comments

To comment on a particular line in SQL, use the double hyphen symbol (- – ). The main purpose of the comments is to explain the process.

![Comments](https://www.syncfusion.com/blogs/wp-content/uploads/2022/02/Comments.png)Other interesting topics like stored procedures, views, and functions will be discussed in our upcoming blogs.

## Summary

Thanks for reading! In this blog, we have covered the basic concepts of SQL that every developer should know. Try out the keywords discussed in this blog post and effectively handle your data.

Syncfusion has over 1,700 components and frameworks for [WinForms](https://www.syncfusion.com/winforms-ui-controls "WinForms UI Controls"), [WPF](https://www.syncfusion.com/wpf-ui-controls "WPF UI Controls"), [WinUI](https://www.syncfusion.com/winui-controls "WinUI Controls"), [.NET MAUI (Preview)](https://www.syncfusion.com/maui-controls ".NET MAUI Controls"), ASP.NET ([Web Forms](https://www.syncfusion.com/jquery/aspnet-web-forms-ui-controls "ASP.NET Web Forms UI Controls"), [MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls "ASP.NET MVC UI Controls"), [Core](https://www.syncfusion.com/aspnet-core-ui-controls "ASP.NET Core UI Controls")), [UWP](https://www.syncfusion.com/uwp-ui-controls "UWP UI Controls"), [Xamarin](https://www.syncfusion.com/xamarin-ui-controls/ "Xamarin UI Controls"), [Flutter](https://www.syncfusion.com/flutter-widgets "Flutter Widgets"), [JavaScript](https://www.syncfusion.com/javascript-ui-controls "JavaScript UI Controls"), [Angular](https://www.syncfusion.com/angular-ui-components "Angular UI Controls"), [Blazor](https://www.syncfusion.com/blazor-components "Blazor UI Components"), [Vue](https://www.syncfusion.com/vue-ui-components "Vue UI Controls"), and [React](https://www.syncfusion.com/react-ui-components "React UI Controls"). Use them to boost your application development speed.

For existing customers, the new Essential Studio version is available for download from the [License and Downloads](https://www.syncfusion.com/account/downloads "License and download page of Essential Studio") page. If you are not yet a Syncfusion customer, you can try our 30-day [free trial](https://www.syncfusion.com/downloads "Free evaluation of the Syncfusion Essential Studio") to check out our newest features.

If you have questions, you can reach us through our [support forums](https://www.syncfusion.com/forums "Syncfusion support forum"),  [support portal](https://support.syncfusion.com/ "Syncfusion support portal"), or [feedback portal](https://www.syncfusion.com/feedback/ "Syncfusion Feedback Portal"). As always, we are happy to assist you!

## Related blogs

- [SQL Server Recovery Models: A Quick Guide](https://www.syncfusion.com/blogs/post/sql-server-recovery-models-a-quick-guide.aspx "SQL Server Recovery Models: A Quick Guide blog")
- [How to Migrate SQL Server in an ASP.NET MVC Application to MySQL and PostgreSQL](https://www.syncfusion.com/blogs/post/how-to-migrate-sql-server-in-an-asp-net-mvc-application-to-mysql-and-postgresql.aspx "Migrate SQL Server in an ASP.NET MVC Application to MySQL and PostgreSQL blog")
- [Top 10 SQL Query Optimization Techniques](https://www.syncfusion.com/blogs/post/top-10-sql-query-optimization-techniques.aspx "Top 10 SQL Query Optimization Techniques blog")
- [How to Export Data from SQL Server to Excel Table in C#](https://www.syncfusion.com/blogs/post/export-data-from-sql-server-to-excel-in-c-sharp.aspx "Export Data from SQL Server to Excel Table in C# blog")