---
title: "SQL – A Complete Guide for Beginners"
published_at: "2022-03-10T11:00:36+00:00"
modified_at: "2024-12-24T08:45:53+00:00"
url: "https://www.syncfusion.com/blogs/post/sql-a-complete-guide-for-beginners"
excerpt: "Nowadays, every organization needs data to run its business. Databases are the best option to store organized collection of data. And, SQL (Structured Query Language) is the most widely used programming language for organizing and retrieving the data in a..."
taxonomy_category:
  - "SQL"
  - "Syncfusion"
  - "Tips and Tricks"
taxonomy_post_tag:
  - "Data Management"
  - "database"
  - "RDBMS"
  - "SQL"
  - "Syncfusion"
---

# SQL – A Complete Guide for Beginners

[Sankar R C P](https://www.syncfusion.com/blogs/author/sankar-pichaimani)

![SQL: A Complete Guide for Beginners](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/SQL%E2%80%94A-Complete-Guide-for-Beginners.png)


Nowadays, every organization needs data to run its business. [Databases](https://en.wikipedia.org/wiki/Database)
 are the best option to store organized collection of data. And, [SQL (Structured Query Language)](https://en.wikipedia.org/wiki/SQL)
 is the most widely used programming 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)

## 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)
:

- 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:**

```
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:**

```
Create table <<table name>>
(
   <<column name1>> datatype,
   <<column name2>> datatype
)
```

**Example:**

![Create keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/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:**

```
Insert into <<table name>>

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

**Example:**

![Insert into keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/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:**

```
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/03/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:**

```
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:**

```
Select distinct * from <<table name>>
```

**Example:**

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

**Syntax:**

```
Select distinct <<column name>> from <<table name>>
```

**Example:**

### ![distinct keyword example](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/distinct-keyword-example.png) #5: top

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

**Syntax:**

```
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:**

```
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:**

```
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:**

```
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:**

```
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:**

```
Select * from <<table name>> where not <<column name>> = <<value>>
```

**Example:**

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

### #10: MIN

This keyword displays the smallest value in a column.

**Syntax:**

```
Select min(<<column name>>>>) from <<table name>>
```

**Example:**

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

This keyword displays the largest value in a column.

**Syntax:**

```
Select max(<<column name>>) from <<table name>>
```

**Example:**

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

### #12: SUM

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

**Syntax:**

```
Select sum(<<column name>>) from <<table name>>
```

**Example:**

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

### #13: in

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

**Syntax:**

```
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:**

```
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:**

```
Select count(*) from <<table name>>
```

**Example:**

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

### #16: AVG

This keyword returns the average value of a column.

**Syntax:**

```
Select avg(<<column name>>) from <<table name>>
```

**Example:**

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

### #17: ANY

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

**Syntax:**

```
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/03/any-keyword.png)

### #18: Like

This keyword retrieves a specified pattern in a column.

**Syntax:**

```
Select * from <<table name>> where <<column name>> like ‘%Value%’
```

**Example:**

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

### #19: UNION

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

**Syntax:**

```
Select * from <<table name1>> 
union
Select * from <<table name2>>
```

**Example:**

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

### #20: Is NULL

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

**Syntax:**

```
Select * from <<table name>> where <<column name>> is null
```

**Example:**

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

### #21: IS NOT NULL

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

**Syntax:**

```
Select * from <<table name>> where <<column name>> is not null
```

**Example:**

![is not null keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/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:**

```
Select * from <<table name>> where <<column name>> like ‘<<value with WildCardValue>>’
```

**Example:**

![WildCards example](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/WildCards-example.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:**

```
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/03/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:**

```
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:**

```
Select * from <<table name>> where <<column name>> between <<value>> and <<value>>
```

**Example:**

![between keyword](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/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:**

```
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:**

```
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:**

```
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:**

```
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)

### #27: Primary Key

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

**Syntax:**

```
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)

### #28: Foreign Key

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

**Syntax:**

```
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)
, [WPF](https://www.syncfusion.com/wpf-ui-controls)
, [WinUI](https://www.syncfusion.com/winui-controls)
, [.NET MAUI (Preview)](https://www.syncfusion.com/maui-controls)
, ASP.NET ([Web Forms](https://www.syncfusion.com/jquery/aspnet-web-forms-ui-controls)
, [MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls)
, [Core](https://www.syncfusion.com/aspnet-core-ui-controls)
), [UWP](https://www.syncfusion.com/uwp-ui-controls)
, [Xamarin](https://www.syncfusion.com/xamarin-ui-controls/)
, [Flutter](https://www.syncfusion.com/flutter-widgets)
, [JavaScript](https://www.syncfusion.com/javascript-ui-controls)
, [Angular](https://www.syncfusion.com/angular-ui-components)
, [Blazor](https://www.syncfusion.com/blazor-components)
, [Vue](https://www.syncfusion.com/vue-ui-components)
, and [React](https://www.syncfusion.com/react-ui-components)
. 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)
 page. If you are not yet a Syncfusion customer, you can try our 30-day [free trial](https://www.syncfusion.com/downloads)
 to check out our newest features.

If you have questions, you can reach us through our [support forums](https://www.syncfusion.com/forums)
, [support portal](https://support.syncfusion.com/)
, or [feedback portal](https://www.syncfusion.com/feedback/)
. 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)
- [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)
- [Top 10 SQL Query Optimization Techniques](https://www.syncfusion.com/blogs/post/top-10-sql-query-optimization-techniques.aspx)
- [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)
