DEV Community

Cover image for Introduction to SQL for Data Analysis
Mugi  Mugendi
Mugi Mugendi

Posted on

Introduction to SQL for Data Analysis

Standard Query Language

Structured Query Language (SQL) is a standard language used to manage relational databases. It is used to create, modify, and query databases by managing the data stored in the tables. SQL is used in a variety of settings, from small businesses to large corporations, and it is essential for anyone who works with data to have a basic understanding of SQL.

This article will provide an introduction to SQL, covering its history, syntax, basic concepts, and some common commands. By the end of this article, readers will have a basic understanding of SQL and be able to start using it to manage data.

History of SQL

SQL was first introduced in the 1970s by IBM researchers Donald Chamberlin and Raymond Boyce. At the time, it was called SEQUEL, which stood for Structured English Query Language. The name was later changed to SQL to avoid trademark issues.

In the 1980s, SQL became the standard language for managing relational databases, and it was adopted by the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO).

Today, SQL is widely used in the tech industry and is an essential skill for anyone who works with data. It is used in a variety of settings, from small businesses to large corporations, and it is essential for anyone who works with data to have a basic understanding of SQL.

Database

A database is a collection of related information
it keeps track of products, and enhances the security of information

Database Management System (DBMS)

It is a special software program that helps users create and maintain a database
it manages large amounts of information, Handles Security, Backups , Import and Export of Data

Types of Database

  1. Relational Database
    Organizes data into one or more tables
    Each table has columns and rows and a unique key identifies each row

  2. Non-Relational Database(no SQL)
    Include documents such as .json, .xml files

Types of Database management systems

  1. Relational Database Management systems(RDBMS).They help users create and maintain Relational DB. They include:
  • mySQL
  • Oracle
  • Postgre SQL
  • MariaDB

Non-RDBMS

They help create and maintain a non-relational database management system. They include:

  • MongoDB
  • DynamoDB
  • Apache

SQL Types

  1. Data Query Language
    • used to query database for information
  2. Data definition Language -defines database schemas
  3. Data Control Language
    • controls access to data in the Database
  4. Data Manipulation Language -used for inserting ,updating and Deleting

SQL syntax

Some of The Most Important SQL Commands

  • SELECT - extracts data from a database
  • UPDATE - updates data in a database
  • DELETE - deletes data from a database
  • INSERT INTO - inserts new data into a database
  • CREATE DATABASE - creates a new database
  • ALTER DATABASE - modifies a database
  • CREATE TABLE - creates a new table
  • ALTER TABLE - modifies a table
  • DROP TABLE - deletes a table
  • CREATE INDEX - creates an index (search key)
  • DROP INDEX - deletes an index

SQL is is used to perform C.R.U.D. operations
C - create
R - Read/retrieve
U - update
D - Delete

CREATE

CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,

);
Enter fullscreen mode Exit fullscreen mode

READ/ RETREIVE

we use the select statement

SELECT column1, column2, ...
FROM table_name
WHERE condition;
Enter fullscreen mode Exit fullscreen mode

UPDATE

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Enter fullscreen mode Exit fullscreen mode

DELETE

DELETE FROM table_name WHERE condition;
Enter fullscreen mode Exit fullscreen mode

SQL JOINS

Image description
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

Different Types of SQL JOINs

Here are the different types of the JOINs in SQL:

(INNER) JOIN: Returns records that have matching values in both tables

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
Enter fullscreen mode Exit fullscreen mode

LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
Enter fullscreen mode Exit fullscreen mode

RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table


SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
Enter fullscreen mode Exit fullscreen mode

FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)