DATA with BARAA

DATA with BARAA

fun with data

SQL Basics

Querying Data

Filtering Data

Joining Tables

SQL Functions

Modifying Data

Defining Data

SQL Elements

In this tutorial, you will learn the basic elements of SQL statements.

The example below is a simple  SELECT statement:

Lets go through all the elements you see !

SQL Statement

SQL statements are coded instructions, which are used to communicate with the database to perform tasks.

SQL statements are not only used to retrieve data from databases, but also perform various tasks, such as creating new tables, updating data and granting permissions.

Comments

The SQL comments in a statement help you to read and maintain the SQL scripts easily.

The DBMS does not execute these comments, and it does not affect the SQL statement behavior as well. And because of that, we use comments to disable the execution of a specific code

Clauses

SQL statements are divided into different parts called clauses that perform specific tasks, which makes writing and reading SQL quite easy.

The most popular clauses are the ones used in SELECT statements. In our example we have 3 clauses:

  • SELECT Clause – the part of the SQL statement where you list the needed columns.
  • FROM Clause – the place where you select the tables involved in the statement.
  • WHERE Clause –  the part of the statement where you define filters on your data.

Keywords

  • keywords are the blue reserved words in SQL.
  • keywords have a predefined meaning in SQL.
  • Keywords are not case-sensitive. It doesn’t matter if you write  SELECT or select.
  • You should avoid using any of these keywords as names of database objects.
  • There are over 900 keywords in SQL. Check MySQL-Keywords to find a complete list of keywords.
  • In our examples the keywords are SELECTFROM,   WHERE, and AND.
.

Identifiers

Identifiers are the names you give to database objects, such as names of tables, columns, views, indexes, and many other objects, as well as the name of the database itself.

In our examples the Identifiers are:

 

  • Column Names first_name, last_name, country, and score
  • Table Name customers

Operators

SQL operators are symbols and keywords can be used to perform certain action.

SQL supports many different types of operators like the following:

  • Arithmetic operators such as  +   
  • Comparison operators such as  <   >  <=   >=
  • Logical operators such as  AND  OR ANY  BETWEEN IN  LIKE NOT
.
Share it !