Mastering SQL basics
As a data scientist, mastering the basics of SQL is crucial. Luckily for you, the basics are pretty easy to grasp, even for non-technical learners. This is because, at this stage, SQL generally reads like English sentences. To get you started, this section focuses on three fundamental components of SQL: the SELECT
, WHERE
, and ORDER
BY
statements.
The SELECT statement
The SELECT statement is the foundation of any SQL query and is used to retrieve data from a database. The general syntax is as follows:
SELECT column1, column2, ..., columnN FROM table_name;
The syntax lists the different columns you want to return, separated by a comma. Since databases hold numerous tables, the query code specifies which table
to select the columns using the FROM
statement. Lastly, the semi-colon (;
) is used to mark the end of a query.
Note
It is standard to create a new line of the query for each main clause (which is capitalized). Here, we started a new line once...