Skip to content

Latest commit

 

History

History
170 lines (89 loc) · 6.8 KB

README.md

File metadata and controls

170 lines (89 loc) · 6.8 KB

SQL: An Introduction

This Repository is designed for people who want to answer questions with data.

@@ I am looking for self-motivated students interested in SQL at different levels! @@

Donate

Youtube Video tutorial

Structured Query Language: An Introduction

If you have any confusion about the code or want to report a bug, please open an issue.

What is SQL?

SQL, or Structured Query Language, is a language designed to allow both technical and non-technical users to query, manipulate, and transform data from a relational database. And due to its simplicity, SQL databases provide safe and scalable storage for millions of websites and mobile applications.

SELECT students FROM sql_course

Did you know?

All strings must be quoted so that the query parser can distinguish words in the string from SQL keywords.

SQL Repository library aims to reduce the time spent writing repositories.

Motivation for this library was the boredom of writing SQL or using query builders to do the same thing over and over again in multiple projects.

SQL Repository allows you to fetch, paginate and operate with data easily without adding overhead and following good practices.

Table Of Contents

=================

Basic Queries:

Query order of execution

  1. FROM and JOINs:

The FROM clause, and subsequent JOINs are first executed to determine the total working set of data that is being queried. This includes subqueries in this clause, and can cause temporary tables to be created under the hood containing all the columns and rows of the tables being joined.

  1. WHERE:

Once we have the total working set of data, the first-pass WHERE constraints are applied to the individual rows, and rows that do not satisfy the constraint are discarded. Each of the constraints can only access columns directly from the tables requested in the FROM clause. Aliases in the SELECT part of the query are not accessible in most databases since they may include expressions dependent on parts of the query that have not yet executed.

  1. GROUP BY:

The remaining rows after the WHERE constraints are applied are then grouped based on common values in the column specified in the GROUP BY clause. As a result of the grouping, there will only be as many rows as there are unique values in that column. Implicitly, this means that you should only need to use this when you have aggregate functions in your query.

  1. HAVING:

If the query has a GROUP BY clause, then the constraints in the HAVING clause are then applied to the grouped rows, discard the grouped rows that don't satisfy the constraint. Like the WHERE clause, aliases are also not accessible from this step in most databases.

  1. SELECT:

Any expressions in the SELECT part of the query are finally computed.

  1. DISTINCT:

Of the remaining rows, rows with duplicate values in the column marked as DISTINCT will be discarded.

  1. ORDER BY:

If an order is specified by the ORDER BY clause, the rows are then sorted by the specified data in either ascending or descending order. Since all the expressions in the SELECT part of the query have been computed, you can reference aliases in this clause.

  1. LIMIT / OFFSET:

Finally, the rows that fall outside the range specified by the LIMIT and OFFSET are discarded, leaving the final set of rows to be returned from the query.

Some helpful codes for SQL are regularly updating in this repositry.

RESOURCES:

CONCLUSION:

We hope the lessons have given you a bit more experience with SQL and a bit more confidence to use SQL with your own data.

Contribution

If you want to contribute some missing examples or fix some bugs, feel free to open an issue or make a pull request.