Quick Intro to SQL Syntax for Beginners
in the previous post we talked already about the basic terms that we should know to be able to start with SQL programming. In this article, we will try to present briefly the syntax of the SQL languages with some mini examples to make things simple and easy for everyone to understand
1. SELECT : SELECT statement is frequently employed. With this statement, we can retrieve data from a database by selecting a table column. For sure, we can select multiple table columns at once, separated by commas. If we want to select all table columns at once, using the star symbol "*" instead of mentioning all the table names will do the job.
2. FROM: With the FORM clause, we decide from which table we are going to retrieve data. So to sum up, a standard SELECT statement looks like this :
SELECT Colum_Names FROM Table_Name ;
3. WHERE: With the WHERE clause, we set a condition to filter data that we want to select. For example, we can select people names from a table where their age is under 30.
4. ORDER BY: With this clause, we can sort the data in descending or ascending way based on certain columns. It's good to know that SQL sorts results in
ascending order by default. To sum up, a SELECT statement can look like this:
SELECT Colum_Names FROM Table_Name WHERE Condition ORDER BY Column_Name DESC;
5. Comments: we can use single line or multi-line comments to give a quick hint about what the SQL statement do.
--this is a single-line comment /* this is a multi-line comment */
6. Semicolons: we find semicolons like in any other programming language at the end of each SQL statement. This separation between SQL Statement is sometimes required when database systems allow executing multiple queries at the same time.
7. Logic operators: like in any other programming language SQL has also similar logic operator such as AND, OR, NOT …etc. for sure there are some special logic operators worth being mentioned such as the LIKE operator to check if a pattern is matched or BETWEEN operator to check if the result is inside a certain range.
8. Case sensitivity: SQL syntax is case-insensitive. It's advised to use uppercase mode when using clauses like WHERE, FROM ...etc. to keep the code always easy for the human eye to be read.