{"id":16523,"date":"2020-07-18T12:38:38","date_gmt":"2020-07-18T07:08:38","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/"},"modified":"2025-07-02T18:37:20","modified_gmt":"2025-07-02T13:07:20","slug":"sql-tutorial-for-beginners","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/","title":{"rendered":"SQL Tutorial: An Introduction to Structured Query Language"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"what-is-sql\">What is SQL?<\/h2>\n\n\n\n<p>SQL, or Structured Query Language, is a programming language used to communicate with relational databases. With the help of SQL, you can retrieve, insert, update, and delete data. SQL is also used to define the structure of databases.<\/p>\n\n\n\n<p>With the help of SQL, you can:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Data Access:<\/strong> Users can access and manipulate data.<\/li>\n\n\n\n<li><strong>Data Retrieval:<\/strong> You can pull specific data from a database.<\/li>\n\n\n\n<li><strong>Database Management:<\/strong> Create, update, modify, and delete database elements.<\/li>\n\n\n\n<li><strong>Structure Definition:<\/strong> Define how a database is organized.<\/li>\n<\/ul>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/practical-sql-training\" class=\"courses-cta-title-link\">SQL Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master SQL and Database management with this SQL course: Practical training with guided projects, AI support, and expert instructors.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>7 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>2 Projects<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/practical-sql-training\" class=\"courses-cta-button\">\n                Take SQL Course Now\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"understanding-databases\">Understanding Databases<\/h2>\n\n\n\n<p>A database is an organized collection of data. Data is information that exists in various forms, like videos, pictures, or text. A database organizes this information for easy access, management, and maintenance.<\/p>\n\n\n\n<p><strong>Examples of databases:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Telephone directories<\/li>\n\n\n\n<li>Customer information<\/li>\n\n\n\n<li>Product inventory records<\/li>\n\n\n\n<li>Visitor registers<\/li>\n\n\n\n<li>Weather records<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-databases-store-data\">How Databases Store Data<\/h3>\n\n\n\n<p>Relational Database Management Systems (RDBMS) store data in tables. Each table uses rows and columns to organize data.<\/p>\n\n\n\n<p><strong>Consider this student data example:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td>ID<\/td><td>Name<\/td><td>Age<\/td><td>Department<\/td><\/tr><\/thead><tbody><tr><td>101<\/td><td>Ross<\/td><td>23<\/td><td>CSE<\/td><\/tr><tr><td>201<\/td><td>Rio<\/td><td>21<\/td><td>Mechanical<\/td><\/tr><tr><td>301<\/td><td>Tina<\/td><td>23<\/td><td>Civil<\/td><\/tr><tr><td>302<\/td><td>Sergio<\/td><td>22<\/td><td>Mechanical<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"key-database-components\">Key Database Components<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Table:<\/strong> A table stores data in a structured way. It uses rows and columns to store data entries.<\/li>\n\n\n\n<li><strong>Field:<\/strong> A field describes each record in a table. For example, in the student table above, <code>ID<\/code>, <code>Name<\/code>, <code>Age<\/code>, and <code>Department<\/code> are fields.<\/li>\n\n\n\n<li><strong>Row (Record):<\/strong> A row, also called a record, provides information about a single entry in a table. Rows appear horizontally in a table.<\/li>\n\n\n\n<li><strong>Column:<\/strong> A column appears vertically in a table and contains information about a specific header, which is the column name. For example, the <code>Age<\/code> column shows all ages.<\/li>\n\n\n\n<li><strong>NULL Values:<\/strong> A <code>NULL<\/code> value means a field has no value. It differs from zero or an empty space.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"data-integrity\">Data Integrity<\/h3>\n\n\n\n<p>Data integrity ensures data remains accurate and consistent. RDBMS has categories for data integrity:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Entity Integrity:<\/strong> Ensures no duplicate rows in a table.<\/li>\n\n\n\n<li><strong>Domain Integrity:<\/strong> Guarantees valid entries for a column based on type, range, and format.<\/li>\n\n\n\n<li><strong>Referential Integrity:<\/strong> Prevents deleting rows used by other records in the table.<\/li>\n\n\n\n<li><strong>User-defined Integrity:<\/strong> Defines specific business rules set by users.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"database-management-system-dbms-operations\">Database Management System (DBMS) Operations<\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/dbms-tutorial\/\">DBMS<\/a> allows you to manage data effectively. Key operations include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Adding new files<\/li>\n\n\n\n<li>Inserting data<\/li>\n\n\n\n<li>Retrieving data<\/li>\n\n\n\n<li>Modifying data<\/li>\n\n\n\n<li>Removing data<\/li>\n\n\n\n<li>Removing files<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"introduction-to-rdbms\">Introduction to RDBMS<\/h2>\n\n\n\n<p>A <a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-rdbms\/\">Relational Database Management System<\/a> (RDBMS) stores data in a structured format, using rows and columns. Data values within each table are related, and tables can also link to other tables. This relational structure allows you to run queries across multiple tables simultaneously.<\/p>\n\n\n\n<p><strong>Features of RDBMS:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>All information stores as tables.<\/li>\n\n\n\n<li>Uses primary keys for unique row identification.<\/li>\n\n\n\n<li>Uses foreign keys to maintain data integrity.<\/li>\n\n\n\n<li>Provides SQL for data access.<\/li>\n\n\n\n<li>Uses indexes for faster data retrieval.<\/li>\n\n\n\n<li>Offers access privileges for data security.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"dbms-vs-rdbms\">DBMS vs. RDBMS<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>DBMS<\/td><td>RDBMS<\/td><\/tr><\/thead><tbody><tr><td>Database Management System<\/td><td>Relational Database Management System<\/td><\/tr><tr><td>Stores data as files<\/td><td>Stores data in tabular form<\/td><\/tr><tr><td>Handles small data<\/td><td>Handles large amounts of data<\/td><\/tr><tr><td>Supports single users<\/td><td>Supports multiple users<\/td><\/tr><tr><td>Examples: XML, file systems<\/td><td>Examples: MySQL, SQL Server, Oracle<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rdbms-vs-traditional-approach\">RDBMS vs. Traditional Approach<\/h3>\n\n\n\n<p>RDBMS applications store data in tabular form. Traditional approaches store data as files, often in hierarchical or navigational forms. In traditional systems, data units may have multiple child nodes but only one parent node, and no inherent \"relation\" between tables like in an RDBMS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-statements-and-syntax\">SQL Statements and Syntax<\/h2>\n\n\n\n<p>SQL statements begin with commands like <code>SELECT<\/code>, <code>INSERT<\/code>, <code>DELETE<\/code>, <code>DROP<\/code>, <code>UPDATE<\/code>, or <code>ALTER<\/code>. They end with a semicolon <code>;<\/code>.<\/p>\n\n\n\n<p><strong>Example:<\/strong><br><code>SELECT column_name FROM table_name;<\/code><\/p>\n\n\n\n<p>The semicolon separates SQL statements. This is standard practice when using multiple SQL statements in one call.<\/p>\n\n\n\n<p>SQL syntax follows a unique set of rules. Keywords include <code>SELECT<\/code>, <code>WHERE<\/code>, <code>UPDATE<\/code>, <code>ORDER BY<\/code>, and <code>HAVING<\/code>.<\/p>\n\n\n\n<p><strong>Basic Syntax Examples:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SQL SELECT:<\/strong> <code>SELECT col1, col2, ... colx<\/code><\/li>\n\n\n\n<li><strong>SQL WHERE:<\/strong><br><pre><code>SELECT col1, col2, ... colx<br>FROM table_name<br>WHERE condition;<\/code><\/pre><br><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-sql-queries-work\">How SQL Queries Work<\/h3>\n\n\n\n<p>When you execute an SQL query, the system determines the best way to fulfill your request. The SQL engine interprets the task and processes the query.<\/p>\n\n\n\n<p>To know how it works, get practice done on <a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-editor-tool\/\">SQL Editor Tool<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"important-sql-commands\">Important SQL Commands<\/h3>\n\n\n\n<p>These are essential <a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\">SQL commands<\/a>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SELECT<\/code>: Extracts data from a database.<\/li>\n\n\n\n<li><code>UPDATE<\/code>: Changes existing data in a database.<\/li>\n\n\n\n<li><code>DELETE<\/code>: Removes data from a database.<\/li>\n\n\n\n<li><code>CREATE TABLE\/DATABASE<\/code>: Builds a new table or database.<\/li>\n\n\n\n<li><code>DROP TABLE\/DATABASE<\/code>: Deletes a table or database.<\/li>\n\n\n\n<li><code>ALTER TABLE\/DATABASE<\/code>: Modifies a table or database.<\/li>\n\n\n\n<li><code>INSERT INTO<\/code>: Adds new data into a database.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"database-normalization\">Database Normalization<\/h2>\n\n\n\n<p>Normalization breaks down large, complex tables into smaller, simpler ones. It organizes your database efficiently, moving data into higher \"normal forms.\"<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"why-you-need-normalization\">Why You Need Normalization<\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/normalization-in-sql\/\">Normalization<\/a> ensures a solid database design and smooth operations. It helps you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create effective database structures.<\/li>\n\n\n\n<li>Run database operations efficiently.<\/li>\n\n\n\n<li>Avoid costly performance issues.<\/li>\n\n\n\n<li>Prevent unnecessary data duplication.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"functional-dependency\">Functional Dependency<\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/functional-dependency-in-dbms\/\">Functional Dependency<\/a> explains how one piece of data (an attribute) is related to another. For example, if you have a \"Student\" record, the Student ID can uniquely determine the Student Name.<\/p>\n\n\n\n<p><strong>Example:<\/strong> In a student course table:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Student ID \u2192 Student Name (One Student ID corresponds to one Name)<\/li>\n\n\n\n<li>Course ID \u2192 Course Name (Each Course ID corresponds to one Course Name)<\/li>\n<\/ul>\n\n\n\n<p><strong>Types of Functional Dependency:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Partial Functional Dependency:<\/strong> An attribute depends on only part of a composite key, not the entire key.<\/li>\n\n\n\n<li><strong>Transitive Dependency:<\/strong> A non-key attribute depends on another non-key attribute.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"normalization-forms\">Normalization Forms<\/h3>\n\n\n\n<p>Database normalization follows specific rules called \"normal forms\":<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First Normal Form (1NF)<\/li>\n\n\n\n<li>Second Normal Form (2NF)<\/li>\n\n\n\n<li>Third Normal Form (3NF)<\/li>\n<\/ul>\n\n\n\n<p><strong>1. First Normal Form (1NF)<\/strong><\/p>\n\n\n\n<p>A table is in 1NF if:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>All data is atomic (each cell contains a single, indivisible value).<\/li>\n\n\n\n<li>There are no repeating groups of columns.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p><strong>Before 1NF:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Student#<\/td><td>Courses<\/td><\/tr><\/thead><tbody><tr><td>101<\/td><td>Math, Science<\/td><\/tr><tr><td>102<\/td><td>History<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>After 1NF:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Student#<\/td><td>Course<\/td><\/tr><\/thead><tbody><tr><td>101<\/td><td>Math<\/td><\/tr><tr><td>101<\/td><td>Science<\/td><\/tr><tr><td>102<\/td><td>History<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>2. Second Normal Form (2NF)<\/strong><\/p>\n\n\n\n<p>A table is in 2NF if:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It is already in 1NF.<\/li>\n\n\n\n<li>No non-key attribute is partially dependent on a primary key. (This applies to tables with composite primary keys).<\/li>\n<\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>Consider a table with a composite primary key (Student#, Course#):<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td>Student#<\/td><td>Course#<\/td><td>Instructor<\/td><\/tr><\/thead><tbody><tr><td>101<\/td><td>M1<\/td><td>Prof. A<\/td><\/tr><tr><td>102<\/td><td>M1<\/td><td>Prof. B<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Here, <code>Instructor<\/code> depends on <code>Course#<\/code> (M1 determines Prof. A\/B). <code>Instructor<\/code> does not depend on the full composite key (Student#, Course#). In 2NF, <code>Instructor<\/code> should move to a separate <code>Course<\/code> table, as it only depends on <code>Course#<\/code>.<\/p>\n\n\n\n<p><strong>3. Third Normal Form (3NF)<\/strong><\/p>\n\n\n\n<p>A table is in 3NF if:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It is already in 2NF.<\/li>\n\n\n\n<li>No transitive dependency exists (non-key attributes do not depend on other non-key attributes).<\/li>\n<\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>Consider a table that is already in 2NF:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Student#<\/td><td>Course#<\/td><td>Instructor<\/td><td>Department<\/td><\/tr><\/thead><tbody><tr><td>101<\/td><td>M1<\/td><td>Prof. A<\/td><td>Math<\/td><\/tr><tr><td>102<\/td><td>M1<\/td><td>Prof. B<\/td><td>Science<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Here, <code>Department<\/code> depends on <code>Instructor<\/code> (Prof. A teaches in Math, Prof. B teaches in Science). <code>Department<\/code> does not depend directly on the primary key (Student#, Course#). In 3NF, <code>Department<\/code> should move to a separate <code>Instructor<\/code> table, as it only depends on <code>Instructor<\/code>, which is a non-key attribute here.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"normalization-pros-and-cons\">Normalization: Pros and Cons<\/h3>\n\n\n\n<p><strong>Advantages:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Based on strong mathematical foundations.<\/li>\n\n\n\n<li>Reduces data redundancy significantly.<\/li>\n\n\n\n<li>Minimizes issues during data inserts, updates, and deletes.<\/li>\n<\/ul>\n\n\n\n<p><strong>Disadvantages:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Can negatively impact data retrieval performance due to more joins.<\/li>\n\n\n\n<li>Might not always perfectly represent complex real-world situations.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-data-types\">SQL Data Types<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-data-types\/\">SQL uses various data types<\/a> for columns:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Numeric:<\/strong> <code>bit<\/code>, <code>tinyint<\/code>, <code>smallint<\/code>, <code>int<\/code>, <code>bigint<\/code>, <code>decimal<\/code>, <code>numeric<\/code>, <code>float<\/code>, <code>real<\/code><\/li>\n\n\n\n<li><strong>Character\/String:<\/strong> <code>Char<\/code>, <code>Varchar<\/code>, <code>Varchar(max)<\/code>, <code>Text<\/code><\/li>\n\n\n\n<li><strong>Date\/Time:<\/strong> <code>Date<\/code>, <code>Time<\/code>, <code>Datetime<\/code>, <code>Timestamp<\/code>, <code>Year<\/code><\/li>\n\n\n\n<li><strong>Unicode Character\/String:<\/strong> <code>Nchar<\/code>, <code>Nvarchar<\/code>, <code>Nvarchar(max)<\/code>, <code>NText<\/code><\/li>\n\n\n\n<li><strong>Binary:<\/strong> <code>Binary<\/code>, <code>Varbinary<\/code>, <code>Varbinary(max)<\/code>, <code>image<\/code><\/li>\n\n\n\n<li><strong>Miscellaneous:<\/strong> <code>Clob<\/code>, <code>Blob<\/code>, <code>Json<\/code>, <code>XML<\/code><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-constraints\">SQL Constraints<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-constraints\/\">SQL Constraints <\/a>enforce rules on data in a table:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Constraint<\/td><td>Description<\/td><\/tr><\/thead><tbody><tr><td>Not Null<\/td><td>Ensures a column cannot have a <code>NULL<\/code> value.<\/td><\/tr><tr><td>Default<\/td><td>Sets a default value for a column if none is specified.<\/td><\/tr><tr><td>Unique<\/td><td>Ensures all values in a column are different.<\/td><\/tr><tr><td>Primary<\/td><td>Uniquely identifies each row\/record in a table.<\/td><\/tr><tr><td>Foreign<\/td><td>Links to a primary key in another table.<\/td><\/tr><tr><td>Check<\/td><td>Ensures all values in a column satisfy conditions.<\/td><\/tr><tr><td>Index<\/td><td>Speeds up data creation and retrieval.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-database-operations\">SQL Database Operations<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"create-database\">CREATE Database<\/h3>\n\n\n\n<p>This statement creates a new database.<br><strong>Syntax:<\/strong> <code>CREATE DATABASE database_name;<\/code><br><strong>Example:<\/strong> <code>CREATE DATABASE testdb;<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"drop-database\">DROP Database<\/h3>\n\n\n\n<p>This command deletes a database. All tables and views within it are also deleted.<br><strong>Syntax:<\/strong> <code>DROP DATABASE database_name;<\/code><br><strong>Example:<\/strong> <code>DROP DATABASE testdb;<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rename-database\">RENAME Database<\/h3>\n\n\n\n<p>This statement changes a database's name.<br><strong>Syntax:<\/strong> <code>RENAME DATABASE old_dbname TO new_dbname;<\/code><br><strong>Example:<\/strong> <code>RENAME testdb TO newdb;<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"select-database\">SELECT Database<\/h3>\n\n\n\n<p>You must select a database before running queries on its tables.<br><strong>Syntax:<\/strong> <code>USE DATABASE database_name;<\/code><br><strong>Example:<\/strong> <code>USE DATABASE newdb;<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-keys\">SQL Keys<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"primary-key\">Primary Key<\/h3>\n\n\n\n<p>A primary key is a column or set of columns that uniquely identifies each row in a table. A primary key is <code>NOT NULL<\/code>, <code>INDEXED<\/code>, and <code>UNIQUE<\/code> by default. If multiple columns form the key, it is a composite primary key.<\/p>\n\n\n\n<p><strong>Syntax (CREATE TABLE):<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCREATE TABLE students(\n    ID INT NOT NULL,\n    Name VARCHAR(255) NOT NULL,\n    Age INT NOT NULL,\n    Department VARCHAR(255),\n    PRIMARY KEY(ID)\n);\n<\/pre><\/div>\n\n\n<p><strong>Syntax (ALTER TABLE):<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nALTER TABLE students\nADD PRIMARY KEY(ID);\n<\/pre><\/div>\n\n\n<p><em>Note: The column must not contain <code>NULL<\/code> values when adding a primary key to an existing table.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"foreign-key\">Foreign Key<\/h3>\n\n\n\n<p>A foreign key links two tables in relational databases. It points to the primary key in another table.<\/p>\n\n\n\n<p><strong>Example:<\/strong><br><strong>First table (Students):<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Student_id<\/td><td>Name<\/td><td>Age<\/td><td>Department<\/td><\/tr><\/thead><tbody><tr><td>101<\/td><td>Ross<\/td><td>23<\/td><td>CSE<\/td><\/tr><tr><td>201<\/td><td>Rio<\/td><td>21<\/td><td>Mechanical<\/td><\/tr><tr><td>301<\/td><td>Tina<\/td><td>23<\/td><td>Civil<\/td><\/tr><tr><td>302<\/td><td>Sergio<\/td><td>22<\/td><td>Mechanical<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Second table (Faculty):<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Faculty_ID<\/td><td>Faculty_Name<\/td><td>Student_id<\/td><\/tr><\/thead><tbody><tr><td>401<\/td><td>Jack<\/td><td>201<\/td><\/tr><tr><td>402<\/td><td>Leo<\/td><td>201<\/td><\/tr><tr><td>403<\/td><td>Harry<\/td><td>301<\/td><\/tr><tr><td>404<\/td><td>Oliver<\/td><td>101<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Here, <code>Student_id<\/code> in the <code>Faculty<\/code> table is a foreign key, referencing <code>Student_id<\/code> (primary key) in the <code>Students<\/code> table.<\/p>\n\n\n\n<p><strong>Syntax (CREATE TABLE with FOREIGN KEY constraint):<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCREATE TABLE Faculty(\n    faculty_ID INT NOT NULL,\n    Faculty_name VARCHAR(255) NOT NULL,\n    Student_id INT NOT NULL,\n    PRIMARY KEY(Student_id),\n    FOREIGN KEY(Student_id) REFERENCES Students(Student_id)\n);\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"primary-key-vs-foreign-key\">Primary Key vs. Foreign Key<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td>Primary Key<\/td><td>Foreign Key<\/td><\/tr><\/thead><tbody><tr><td>Cannot be <code>NULL<\/code><\/td><td>Can be <code>NULL<\/code><\/td><\/tr><tr><td>Always unique<\/td><td>Can have duplicate values<\/td><\/tr><tr><td>Uniquely identifies a record in a table<\/td><td>Links to a primary key in another table<\/td><\/tr><tr><td>Only one primary key per table<\/td><td>Multiple foreign keys can exist<\/td><\/tr><tr><td>Adds a clustered index by default<\/td><td>Does not automatically create an index<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"composite-key\">Composite Key<\/h3>\n\n\n\n<p>A composite key combines two or more fields or columns in a table.<br><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCREATE TABLE table_name(\n    col1 INT,\n    col2 INT,\n    col3 VARCHAR(50),\n    PRIMARY KEY (col1, col2)\n);\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"unique-key\">Unique Key<\/h3>\n\n\n\n<p>A unique key identifies a record uniquely within a table. Both unique keys and primary keys provide uniqueness for columns.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"alternate-key\">Alternate Key<\/h3>\n\n\n\n<p>An alternate key is a candidate key not chosen as the primary key. If a table has multiple candidate keys, one becomes primary, and others are alternate keys.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-table-operations\">SQL Table Operations<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"create-table\">CREATE TABLE<\/h3>\n\n\n\n<p>This statement creates tables in a database.<br><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCREATE TABLE table_name (\n    column 1 &quot;data type&quot;,\n    column 2 &quot;data type&quot;,\n    ...\n    column x &quot;data type&quot;\n);\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"drop-table\">DROP TABLE<\/h3>\n\n\n\n<p>This command deletes a table from the database.<br><strong>Syntax:<\/strong> <code>DROP TABLE \"table_name\";<\/code><br><strong>Example:<\/strong> <code>DROP TABLE student;<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"delete-table-rows\">DELETE TABLE (Rows)<\/h3>\n\n\n\n<p>This command deletes rows from a table. Use a <code>WHERE<\/code> condition to delete specific rows.<br><strong>Syntax:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>DELETE FROM table_name;<\/code> (Deletes all rows)<\/li>\n\n\n\n<li><code>DELETE FROM table_name WHERE condition;<\/code> (Deletes specific rows)<\/li>\n<\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>DELETE FROM student;<\/code><\/li>\n\n\n\n<li><code>DELETE FROM student WHERE student_id = 2;<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"alter-table\">ALTER TABLE<\/h3>\n\n\n\n<p>This command adds, modifies, or deletes columns in an existing table.<br><strong>Syntax (ADD Column):<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nALTER TABLE table_name\nADD (\n    col1 col_definition,\n    col2 col_definition,\n    ...\n    colx col_definition\n);\n<\/pre><\/div>\n\n\n<p><strong>Syntax (MODIFY Column):<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nALTER TABLE table_name\nMODIFY (\n    col1 col_definition,\n    col2 col_definition,\n    ...\n    colx col_definition\n);\n<\/pre><\/div>\n\n\n<p><strong>Syntax (DROP Column):<\/strong><br><code>ALTER TABLE table_name DROP COLUMN column_name;<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rename-table\">RENAME TABLE<\/h3>\n\n\n\n<p>This command changes a table's name.<br><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nALTER TABLE table_name\nRENAME TO new_table_name;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-command-groups\">SQL Command Groups<\/h2>\n\n\n\n<p>There are some <a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\">types of SQL commands<\/a>, these are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DDL (Data Definition Language):<\/strong> Creates and modifies database objects.<\/li>\n\n\n\n<li><strong>DML (Data Manipulation Language):<\/strong> Manipulates data within objects.<\/li>\n\n\n\n<li><strong>DCL (Data Control Language):<\/strong> Manages database permissions.<\/li>\n\n\n\n<li><strong>TCL (Transaction Control Language):<\/strong> Saves and restores database changes.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ddl-data-definition-language\">DDL \u2013 Data Definition Language<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Command<\/td><td>Description<\/td><\/tr><\/thead><tbody><tr><td>Create<\/td><td>Creates database objects<\/td><\/tr><tr><td>Alter<\/td><td>Alters database object structures<\/td><\/tr><tr><td>Drop<\/td><td>Deletes objects from the database<\/td><\/tr><tr><td>Truncate<\/td><td>Permanently removes all records from a table<\/td><\/tr><tr><td>Rename<\/td><td>Renames an object<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Examples:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>CREATE TABLE:<\/strong><br><pre><code>CREATE TABLE employees (<br>    emp_id INT (10) NOT NULL,<br>    first_name VARCHAR(10),<br>    last_name VARCHAR(10) NOT NULL,<br>    salary INT(10) NOT NULL,<br>    PRIMARY KEY (emp_id)<br>);<\/code><\/pre><br><\/li>\n\n\n\n<li><strong>ALTER TABLE (Add Column):<\/strong> <code>ALTER TABLE employees ADD COLUMN contact INT(10);<\/code><\/li>\n\n\n\n<li><strong>ALTER TABLE (Rename Column):<\/strong> <code>ALTER TABLE employees RENAME COLUMN contact TO job_code;<\/code><\/li>\n\n\n\n<li><strong>TRUNCATE TABLE:<\/strong> <code>TRUNCATE TABLE employees;<\/code><\/li>\n\n\n\n<li><strong>DROP TABLE:<\/strong> <code>DROP TABLE table_name;<\/code> or <code>DROP TABLE employees;<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"dml-data-manipulation-language\">DML \u2013 Data Manipulation Language<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Command<\/td><td>Description<\/td><\/tr><\/thead><tbody><tr><td>Insert<\/td><td>Inserts data into a table<\/td><\/tr><tr><td>Update<\/td><td>Updates existing data within a table<\/td><\/tr><tr><td>Delete<\/td><td>Deletes specified or all records from a table<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Examples:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>INSERT INTO:<\/strong><br><pre><code>INSERT INTO employees (emp_id, first_name, last_name, salary)<br>VALUES (101, 'Steven', 'King', 10000);<\/code><\/pre><br><\/li>\n\n\n\n<li><strong>UPDATE:<\/strong><br><pre><code>UPDATE employees<br>SET last_name='Cohen'<br>WHERE emp_id=101;<\/code><\/pre><br><\/li>\n\n\n\n<li><strong>DELETE FROM:<\/strong><br><code>DELETE FROM employees WHERE emp_id IN (101, 103);<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"dcl-data-control-language\">DCL \u2013 Data Control Language<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Command<\/td><td>Description<\/td><\/tr><\/thead><tbody><tr><td>Grant<\/td><td>Gives access privileges to the database<\/td><\/tr><tr><td>Revoke<\/td><td>Withdraws access privileges<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tcl-transaction-control-language\">TCL \u2013 Transaction Control Language<\/h3>\n\n\n\n<p>TCL manages transactions in the database.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Command<\/td><td>Description<\/td><\/tr><\/thead><tbody><tr><td>Commit<\/td><td>Saves the work done<\/td><\/tr><tr><td>Rollback<\/td><td>Restores the database to its state since the last commit<\/td><\/tr><tr><td>Savepoint<\/td><td>Identifies a point in a transaction for later rollback<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-operators\">SQL Operators<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-operators\/\">SQL operators<\/a> are special keywords or characters that you use in SQL statements. You use them within the <code>WHERE<\/code> clause to perform specific operations. These operations help you compare values, combine multiple conditions, or perform calculations, which allows you to filter, modify, or analyze data based on defined criteria.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"sql-arithmetic-operators\">SQL Arithmetic Operators<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Operator<\/td><td>Description<\/td><\/tr><\/thead><tbody><tr><td><code>+<\/code><\/td><td>Adds values of both operands<\/td><\/tr><tr><td><code>-<\/code><\/td><td>Subtracts the right-hand operand from the left<\/td><\/tr><tr><td><code>*<\/code><\/td><td>Multiplies both operands<\/td><\/tr><tr><td><code>\/<\/code><\/td><td>Divides the left-hand operand by the right<\/td><\/tr><tr><td><code>%<\/code><\/td><td>Divides and returns the remainder<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Example:<\/strong> In <code>X + Y<\/code> or <code>X * Y<\/code>, <code>X<\/code> is the left operand and <code>Y<\/code> is the right operand.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"sql-logical-operators\">SQL Logical Operators<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td>Operator<\/td><td>Description<\/td><td>Example<\/td><td>Result<\/td><\/tr><\/thead><tbody><tr><td><code>AND<\/code><\/td><td>True if all conditions separated by <code>AND<\/code> are true<\/td><td><code>(5&lt;2) AND (5&gt;3)<\/code><\/td><td><code>FALSE<\/code><\/td><\/tr><tr><td><code>OR<\/code><\/td><td>True if any condition separated by <code>OR<\/code> is true<\/td><td><code>(5&lt;2) OR (5&gt;3)<\/code><\/td><td><code>TRUE<\/code><\/td><\/tr><tr><td><code>LIKE<\/code><\/td><td>Compares a value to similar patterns using wildcards<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><code>BETWEEN<\/code><\/td><td>Checks if an attribute value is within a range<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><code>NOT<\/code><\/td><td>Displays records where the condition is <code>NOT TRUE<\/code><\/td><td><code>NOT(5&lt;2)<\/code><\/td><td><code>TRUE<\/code><\/td><\/tr><tr><td><code>IN<\/code><\/td><td>True if the operand matches any value in a list<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><tr><td><code>ISNULL<\/code><\/td><td>Compares a value with a <code>NULL<\/code> value<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Sample Queries:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SELECT * FROM employees WHERE salary BETWEEN 10000 AND 20000;<\/code><\/li>\n\n\n\n<li><code>SELECT * FROM employees WHERE first_name LIKE \u2018Steven\u2019;<\/code><\/li>\n\n\n\n<li><code>SELECT * FROM employees WHERE salary IS NULL;<\/code><\/li>\n\n\n\n<li><code>SELECT * FROM employees WHERE salary IN (10000, 12000, 20000);<\/code><\/li>\n\n\n\n<li><code>SELECT DISTINCT(first_name) FROM employees;<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"sql-comparison-operators\">SQL Comparison Operators<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Operator<\/td><td>Description<\/td><\/tr><\/thead><tbody><tr><td><code>=<\/code><\/td><td>Equal to<\/td><\/tr><tr><td><code>&gt;<\/code><\/td><td>Greater than<\/td><\/tr><tr><td><code>&gt;=<\/code><\/td><td>Greater than or equal to<\/td><\/tr><tr><td><code>&lt;<\/code><\/td><td>Less than<\/td><\/tr><tr><td><code>&lt;=<\/code><\/td><td>Less than or equal to<\/td><\/tr><tr><td><code>&lt;&gt;<\/code> or <code>!=<\/code><\/td><td>Not equal to<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Sample Queries:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SELECT * FROM employees WHERE first_name = \u2018Steven\u2019 AND salary &lt;= 10000;<\/code><\/li>\n\n\n\n<li><code>SELECT * FROM employees WHERE first_name = \u2018Steven\u2019 OR salary &gt;= 10000;<\/code><\/li>\n\n\n\n<li><code>SELECT * FROM employees WHERE first_name = \u2018Steven\u2019 AND salary &lt;&gt; 10000;<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-aggregate-functions\">SQL Aggregate Functions<\/h2>\n\n\n\n<p>Aggregate functions perform calculations on sets of rows and return a single value:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td>Function<\/td><td>Description<\/td><\/tr><\/thead><tbody><tr><td><code>Avg()<\/code><\/td><td>Returns the average value from specified columns<\/td><\/tr><tr><td><code>Count()<\/code><\/td><td>Returns the number of table rows<\/td><\/tr><tr><td><code>Max()<\/code><\/td><td>Returns the largest value among records<\/td><\/tr><tr><td><code>Min()<\/code><\/td><td>Returns the smallest value among records<\/td><\/tr><tr><td><code>Sum()<\/code><\/td><td>Returns the sum of specified column values<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Sample Queries:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SELECT AVG(salary) FROM employees;<\/code><\/li>\n\n\n\n<li><code>SELECT COUNT(*) FROM employees;<\/code><\/li>\n\n\n\n<li><code>SELECT MIN(salary) FROM employees;<\/code><\/li>\n\n\n\n<li><code>SELECT MAX(salary) FROM employees;<\/code><\/li>\n\n\n\n<li><code>SELECT SUM(salary) FROM employees;<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-clauses\">SQL Clauses<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"where-clause\">WHERE Clause<\/h3>\n\n\n\n<p>The <code>WHERE<\/code> clause specifies a condition when fetching data. It works with <code>SELECT<\/code>, <code>UPDATE<\/code>, and <code>DELETE<\/code> statements.<br><strong>Example:<\/strong> <code>SELECT * FROM employees WHERE emp_id = 101;<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"group-by-clause\">GROUP BY Clause<\/h3>\n\n\n\n<p>The <code>GROUP BY<\/code> clause arranges identical data into groups. It follows the <code>WHERE<\/code> clause and precedes the <code>ORDER BY<\/code> clause.<br><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT SUM(salary), dept_id\nFROM employees\nWHERE salary &gt;= 15000\nGROUP BY dept_id;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"having-clause\">HAVING Clause<\/h3>\n\n\n\n<p>The <code>HAVING<\/code> clause filters groups based on aggregate functions. It must follow <code>GROUP BY<\/code> and precede <code>ORDER BY<\/code>.<br><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT AVG(salary), dept_id\nFROM employees\nWHERE salary &gt;= 10000\nGROUP BY dept_id\nHAVING COUNT(dept_id) &gt;= 2;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"order-by-clause\">ORDER BY Clause<\/h3>\n\n\n\n<p>The <code>ORDER BY<\/code> clause sorts the output of a <code>SELECT<\/code> statement. Default sort order is ascending (<code>ASC<\/code>). Use <code>DESC<\/code> for descending order.<br><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT * FROM employees\nORDER BY salary DESC;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-set-operators\">SQL Set Operators<\/h2>\n\n\n\n<p>Set operators combine results of two or more <code>SELECT<\/code> statements.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"union-all\">UNION ALL<\/h3>\n\n\n\n<p><code>UNION ALL<\/code> combines results from two <code>SELECT<\/code> statements, including duplicate rows.<br><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT a.col1, b.col2, ..., a.coln FROM table1 a, table2 b WHERE a.commonfield = b.commonfield\nUNION ALL\nSELECT a.col1, b.col2, ..., a.coln FROM table1 a, table2 b WHERE a.commonfield = b.commonfield;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"union\">UNION<\/h3>\n\n\n\n<p><code>UNION<\/code> combines result-sets of two or more <code>SELECT<\/code> statements, removing duplicates.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Each <code>SELECT<\/code> statement must have the same number of columns.<\/li>\n\n\n\n<li>Columns must have similar data types and be in the same order.<\/li>\n\n\n\n<li>You can combine multiple queries with several <code>UNION<\/code> statements.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-joins\">SQL JOINS<\/h2>\n\n\n\n<p>A <a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-joins\/\">SQL <code>JOIN<\/code> <\/a>combines rows or columns from multiple tables based on a related column.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>INNER JOIN:<\/strong> Returns rows where there's a match in both tables.<\/li>\n\n\n\n<li><strong>LEFT JOIN:<\/strong> Returns all rows from the left table, plus matched rows from the right. Returns <code>NULL<\/code> for unmatched rows in the right table.<\/li>\n\n\n\n<li><strong>RIGHT JOIN:<\/strong> Returns all rows from the right table, plus matched rows from the left. Returns <code>NULL<\/code> for unmatched rows in the left table.<\/li>\n\n\n\n<li><strong>FULL OUTER JOIN:<\/strong> Combines results of left and right outer joins. Returns all records from both tables, with <code>NULL<\/code> for missing matches.<\/li>\n\n\n\n<li><strong>SELF JOIN:<\/strong> Joins a table to itself, treating it as two separate tables by renaming one.<\/li>\n\n\n\n<li><strong>CARTESIAN JOIN (CROSS JOIN):<\/strong> Returns the Cartesian product of records from two or more tables.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"sql-inner-join\">SQL INNER JOIN<\/h3>\n\n\n\n<p><code>INNER JOIN<\/code> creates a new result table by combining column values from two tables based on a join condition.<br><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT table1.col1, table2.col2, ..., table1.coln\nFROM table1\nINNER JOIN table2\nON table1.commonfield = table2.commonfield;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"sql-left-join\">SQL LEFT JOIN<\/h3>\n\n\n\n<p><code>LEFT JOIN<\/code> returns all values from the left table and matched values from the right table. It returns <code>NULL<\/code> if no match exists in the right table.<br><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT table1.col1, table2.col2, ..., table1.coln\nFROM table1\nLEFT JOIN table2\nON table1.commonfield = table2.commonfield;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"sql-right-join\">SQL RIGHT JOIN<\/h3>\n\n\n\n<p><code>RIGHT JOIN<\/code> returns all values from the right table and matched values from the left table. It returns <code>NULL<\/code> if no match exists in the left table.<br><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT table1.col1, table2.col2, ..., table1.coln\nFROM table1\nRIGHT JOIN table2\nON table1.commonfield = table2.commonfield;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"sql-full-outer-join\">SQL FULL OUTER JOIN<\/h3>\n\n\n\n<p><code>FULL OUTER JOIN<\/code> combines results from both <code>LEFT JOIN<\/code> and <code>RIGHT JOIN<\/code>. The result includes all records from both tables, filling in <code>NULL<\/code> for unmatched records.<br><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT table1.col1, table2.col2, ..., table1.coln\nFROM table1\nLEFT JOIN table2\nON table1.commonfield = table2.commonfield\nUNION\nSELECT table1.col1, table2.col2, ..., table1.coln\nFROM table1\nRIGHT JOIN table2\nON table1.commonfield = table2.commonfield;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"sql-self-join\">SQL SELF JOIN<\/h3>\n\n\n\n<p><code>SELF JOIN<\/code> joins a table to itself. You must temporarily rename at least one table in the SQL statement.<br><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT a.col1, b.col2, ..., a.coln\nFROM table1 a, table1 b\nWHERE a.commonfield = b.commonfield;\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"sql-cross-join\">SQL CROSS JOIN<\/h3>\n\n\n\n<p><code>CROSS JOIN<\/code> creates a result set where the number of rows equals the product of the rows in the joined tables.<br><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT table1.col1, table2.col2, ..., table1.coln\nFROM table1\nCROSS JOIN table2;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"sql-faqs\">SQL FAQs<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-are-the-basics-to-learn-sql\">What are the basics to learn SQL?<\/h3>\n\n\n\n<p>SQL stands for Structured Query Language. It operates databases. To learn SQL basics, understand what SQL means and learn fundamental query syntax. Knowing different database management systems, RDBMS, and SQL commands helps you learn the basics.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-long-does-it-take-to-learn-sql-for-beginners\">How long does it take to learn SQL for beginners?<\/h3>\n\n\n\n<p>The time to learn SQL varies per person. Two to three weeks is generally enough to learn the basics and start working with databases. Becoming highly efficient takes longer.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"is-sql-good-for-beginners\">Is SQL good for beginners?<\/h3>\n\n\n\n<p>SQL is widely used in companies. It is an excellent choice for beginners to enter programming.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"where-can-i-learn-sql-for-beginners\">Where can I learn SQL for beginners?<\/h3>\n\n\n\n<p>Many resources help beginners learn SQL. Learn from blog posts, YouTube content, books, or <a href=\"https:\/\/www.mygreatlearning.com\/sql\/free-courses\">free SQL courses<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"is-sql-coding\">Is SQL coding?<\/h3>\n\n\n\n<p>SQL stands for structured query language and it is a programming language. The main purpose of SQL is to communicate with relational databases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"is-sql-easier-than-python\">Is SQL easier than Python?<\/h3>\n\n\n\n<p>In terms of grammar and the amount of concepts to be learnt, SQL is simpler. However, as a tool, SQL may be more difficult. We cannot really compare the two as they are both easy to use in their own ways and for different purposes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"can-i-get-a-job-if-i-know-sql\">Can I get a job if I know SQL?<\/h3>\n\n\n\n<p>Yes, you can get a job with SQL skills. SQL is one of the most widely used programming languages, and recruiters actively seek individuals with SQL knowledge.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"should-i-learn-sql-or-python-first\">Should I learn SQL or Python first?<\/h3>\n\n\n\n<p>Both Python and SQL are in high demand. Learning Python fundamentals first, then adding SQL for data manipulation, can be an effective approach. You can choose either based on your goals.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL is the language for managing databases. It helps you interact with data, perform database operations, and build applications.<\/p>\n<p>This guide helps you learn SQL from the ground up. You will learn what SQL is, how databases work, and essential commands to manage your data.<\/p>\n","protected":false},"author":41,"featured_media":17434,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36844],"content_type":[],"class_list":["post-16523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-sql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SQL Tutorial for Beginners<\/title>\n<meta name=\"description\" content=\"This guide helps you learn SQL from the ground up. You will learn what SQL is, how databases work, and essential commands to manage your data.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Tutorial: An Introduction to Structured Query Language\" \/>\n<meta property=\"og:description\" content=\"This guide helps you learn SQL from the ground up. You will learn what SQL is, how databases work, and essential commands to manage your data.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-18T07:08:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-02T13:07:20+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"700\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"SQL Tutorial: An Introduction to Structured Query Language\",\"datePublished\":\"2020-07-18T07:08:38+00:00\",\"dateModified\":\"2025-07-02T13:07:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/\"},\"wordCount\":2732,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Featured-Images-for-Articles-01.jpg\",\"keywords\":[\"sql\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/\",\"name\":\"SQL Tutorial for Beginners\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Featured-Images-for-Articles-01.jpg\",\"datePublished\":\"2020-07-18T07:08:38+00:00\",\"dateModified\":\"2025-07-02T13:07:20+00:00\",\"description\":\"This guide helps you learn SQL from the ground up. You will learn what SQL is, how databases work, and essential commands to manage your data.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Featured-Images-for-Articles-01.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Blog-Featured-Images-for-Articles-01.jpg\",\"width\":1000,\"height\":700},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-tutorial-for-beginners\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Tutorial: An Introduction to Structured Query Language\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Tutorial for Beginners","description":"This guide helps you learn SQL from the ground up. You will learn what SQL is, how databases work, and essential commands to manage your data.","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:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/","og_locale":"en_US","og_type":"article","og_title":"SQL Tutorial: An Introduction to Structured Query Language","og_description":"This guide helps you learn SQL from the ground up. You will learn what SQL is, how databases work, and essential commands to manage your data.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2020-07-18T07:08:38+00:00","article_modified_time":"2025-07-02T13:07:20+00:00","og_image":[{"width":1000,"height":700,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"SQL Tutorial: An Introduction to Structured Query Language","datePublished":"2020-07-18T07:08:38+00:00","dateModified":"2025-07-02T13:07:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/"},"wordCount":2732,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg","keywords":["sql"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/","url":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/","name":"SQL Tutorial for Beginners","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg","datePublished":"2020-07-18T07:08:38+00:00","dateModified":"2025-07-02T13:07:20+00:00","description":"This guide helps you learn SQL from the ground up. You will learn what SQL is, how databases work, and essential commands to manage your data.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg","width":1000,"height":700},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-tutorial-for-beginners\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"SQL Tutorial: An Introduction to Structured Query Language"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg",1000,700,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01-300x210.jpg",300,210,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01-768x538.jpg",768,538,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg",1000,700,false],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg",1000,700,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg",1000,700,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg",640,448,false],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg",96,67,false],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/07\/Blog-Featured-Images-for-Articles-01.jpg",150,105,false]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"SQL is the language for managing databases. It helps you interact with data, perform database operations, and build applications. This guide helps you learn SQL from the ground up. You will learn what SQL is, how databases work, and essential commands to manage your data.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=16523"}],"version-history":[{"count":31,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16523\/revisions"}],"predecessor-version":[{"id":109845,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16523\/revisions\/109845"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/17434"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=16523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=16523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=16523"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=16523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}