INTRODUCTION TO SQL
Published: 2023-02-16 10:00:27

**
![SQL BASICS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4iuu043upfqt4b48mpqw.jpg)**
****SQL in full is structured query language. SQL can be defined as a computer programming language that allows you to manipulate, retrieve and store  data in a database.

SQL is mostly used with relational databases. Relational databases are databases that contains a set of data where all the items are related. There are two important aspects in relational databases a primary key and a foreign key. A primary key is a unique identifier for each record and it cannot be duplicated or contain a null value.

Databases have tables, columns and rows which is important to understand since it will help in the querying. When writing an SQL query you use a full stop (.) to separate the dataset name and the table name. For example; If you have customer information stored in a dataset called customer_ data and it has a table called customer_ name. The SElECT CLAUSE will be;
``
SELECT
customer_ data.customer_name 

Column names are separated using commas.For example;
 

```
SELECT
customer_id,
first_name,
last_name,
``
This three clauses are some of the basic ones in SQl that are used in most queries:
1.SELECT- it allows you to choose the columns you want to return

2.FROM- it allows you to choose the tables where the columns you want are located

3.WHERE-it allows you to filter certain information

For example;
``
SELECT
first_name
FROM
customer_data.customer_name
WHERE
first_name='Tony'


## ADVANTAGES OF SQL

1. Faster querying process-large data is processed quickly and efficiently since execution time of queries is short.

2.Easy to understand-it uses simple English keywords like SELECT,INSERT,DELETE which are easy to understand.

3.Commonality-it is used with various It systems and can be used with multiple languages.

4.Flexibility-it can be used on computers ,pc and tablets

##  SOME SQL CLAUSES

1. DISTINCT-used to remove duplicates
  
SELECT 
DISTINCT customer_id
FROM
customer_data.customer_address

2.CAST()-used to convert data from one data type to another

SELECT
CAST(purchase_price AS FLOAT 64)
FROM
customer_data.customer_purchase
ORDER BY
CAST(purchase _price AS FLOAT64) DESC
This query will convert the purchase price to a float data type and will show the results in Descending order

3.UPDATE-it is used to update records in a table
UPDATE
cars.car_info
SET
num_of_doors="four"
WHERE
make="dodge"
AND fuel_type="gas"
This query will update the number of doors to be four for where the conditions specified are meet.

4.DELETE-used to remove one or more records.

5.ORDER BY-is used to state how the results will be displayed.If you put DESC it will display the results in Descending order otherwise it automatically assumes in ascending order.

6.CONCAT()-used to add strings together to create new text strings that can be used as unique keys.

SELECT
CONCAT(product_code,product_color) AS new_product_code
FROM
customer_data.customer_purchase
WHERE
product='couch'

Here the strings from product code and product color will be combined to form a new product code for the conditions specified

For more articles [](url)https://learnsql.com/blog/sql-basics-cheat-sheet/