Skip to main content

SQL - Part 1

                                            SQL tutorial from scratch -- Part 1


Before going deep dive into in SQL I want to explain the main purpose of DB(database).
Suppose we have large amount of data (for example it would be the students in the same class), and we want to create some website which is give us all information about them. How we do it. Of course using database.Maybe you ask yourself questions: "I can store them in file or array". Yes you is exactly right. But imagine you have large amount of data and if you store them in file or array your program/website will work very hard. Now let's visualize databases:

As we can see it is one of the basic db type which is store title, release_year, length and replacement_cost.

Don't worry about DB if you don't understand them very well. Our next paragraphs will explain it more accurately and also I try to add some important images.

                    "Yes I know that right now you think 🤔 what is SQL"

Okay, SQL is stands for Structured Query Language and it is one of the most popular Database system in the world. But of course there are other types which is MS Access, Oracle DB, MS SQL and so on. So what SQL can do?

SQL can:

  • Manipulate data
  • Update data
  • Delete data
  • Insert data
  • Create table, db etc.
  • Retrieve data from db.
Generally DB systems divided into two parts: Relational and non-relational db systems
We can say an example for relational database systems--> MySQL.
We can say an example for non-relational database systems--> No SQL.

We can use SQL in our website. For example you have a lot of books and you want to store them in your website. For doing it first you must store them in SQL and easily call them in your website.

To do it we need:

  • RDBMS(Relational Database Management System)
  • Server side scripting language like Java, C#, or PHP, etc.
  • To use SQL to get data
  • For designing HTML, CSS, JS (JavaScript)
 Now let's closer look at SQL syntax. To working in SQL first we must create some table
The picture which is given below explain it more accurately.
So we have three columns and first column's name is first_name(for storing names of customers)
Second column's name is last_name (for storing last name of customers) 
And last column's name is email (for storing emails of customers)
                                       Image result for some sql table

Later paragraphs you will learn how to edit the columns of given table(Delete, Update, Insert)

And now it is time to learn SQL. SQL have some keywords which is very important Keyword is special words in programming which is doing some operation
In SQL keywords isn't case-sensitive it means that for example 'Select', 'SELECT', 'sElEcT' keywords are the same. After each SQL statement we must put semicolon sign otherwise it will cause an error.
In standard it is accepted that every SQL keyword must write in upper-case letter.

                   Some of the most important SQL keywords

  • 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 db
  • ALERT 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

                                  SELECT- keyword

In SQL SELECT keyword is used to select data from database.

We can write the general formula for SELECT like this:

SELECT columnName1, columnName2,... FROM databaseName; (don't forget semicolon sign)

And if we want to select all information from table then we write:

SELECT * FROM databaseName;

Let's suppose its name would be 'users'

                                                  Related image

If we write SELECT * FROM users; then we can see all information which is given in the users table

When we write SELECT first_name FROM users; then we just can see only names of users.

Suppose you want to retrieve distinct(different from other) information from table. To execute it we use DISTINCT keyword.

Let's suppose our table's name is 'employers'

Related image

For example we want to choose distinct year of birth. For doing it we just write:

SELECT DISTINCT Year_of_birth FROM employers;

Result would be:

Because 1974 repeated there 3 or more times DISTINCT keyword removes them and keep only one.

If we want to count the number of birth years which is different then we can do it as below:

SELECT COUNT(DISTINCT Year_of_birth) FROM employers;

Result would be : 6 (you can verify this).

I think it is enough for you about SELECT keyword. But remember after reading about keyword you must practice yourself otherwise the result would be bad.

Number of page views:
 page counters


Popular posts from this blog

A simple calculator for adding and subtracting in c++

A simple calculator for adding and subtracting in c++

In this post, I write a code about very simple calculator in c++. Actually it is the problem in
If you're not familiar with this website then you can go below link:

Input is in this form : 

                                             x+5=2  or 1+x=4  or  1+4=x
In the output we give the value of x.

It has very simple solution. That's why i give there only code and when you read this code line-by-line you easily understand it     :)


#include<iostream>#include<string>using namespace std;int main(){ string statement;cin>>statement; int last_number = 0; if(statement[statement.length()-1] == '0' || statement[statement.length()-1] == '1'|| statement[statement.length()-1] == '2' || statement[statement.length()-1] == '3'|| statement[statement.length()-1] == '4' || statement[statement.length()-1] == '…

Java Proqramlashdirma Dili

1) Dostlar bu blogda java proqramlasdirma dili haqqinda melumat verecyik

Java proqramlasdirma dili high level programming language sinfine daxildir bu proqramlasdirma dili muxtelif platformalarda calisirki bu da onun ustun cehetlerinden biridir. Java proqramladirma diline oxshar dillere misal olaraq C, C#, C++ misal gostermek olar. Bunu qeyd etmek kifayetdir ki eger siz sadaladigim dillerden hec olmasa birini mukemmel bilsez o biri diller sizin ucun su kimi asan olar. Yeni esas sizin OOP den basiniz cixmalidir birdeki alqoritmleri derinden menisemek lazimdir. Eger alqoritmleri derinden menimsemek isteyirsinizse sizin sade riyazi biliklerden basinziz cixmalidir eks halda alqoritme geldikde sizin ucun cetin ola biler. Lakin size sad xeberim var, hetta riyzi bilikleriniz o qeder de yaxi deyilse de siz oz alqortim biliklerinizi tekmillesdir bilersiniz bunun ucun her movzudaki alqoritmlere aid coxlu mesele, misal hell etmek ve partnyorunuzla muzakire etmelisiniz . Bu muzakire etmek meseles…