Science Knowings: JavaScript Course For Social Media

Database Query Languages (SQL, GraphQL)

Previous Topic: Graph Databases (Neo4j) → Database Query Languages (SQL, GraphQL)

In our previous session, we explored Graph Databases (Neo4j) to understand how to work with connected data. Today, we're shifting gears to learn about Database Query Languages, particularly SQL and GraphQL, which play a crucial role in data retrieval and manipulation. Let's dive in!

Why SQL?

SQL (Structured Query Language) has been around for decades and remains widely used for relational databases. It's a robust and versatile language that allows you to query, update, and manage data efficiently.

What is SQL?

SQL is a declarative language, meaning you specify what you want to do with the data without specifying how to do it. It uses a set of commands like SELECT, INSERT, UPDATE, and DELETE to interact with databases.

SQL Syntax

SQL syntax is fairly straightforward. Commands are followed by clauses that specify the data and operations to be performed. For instance, the SELECT command retrieves data from a table, while the WHERE clause filters the results.

SELECT Statement

The SELECT statement is the most fundamental SQL command. It allows you to retrieve specific columns or rows from a table. For example: SELECT * FROM customers WHERE name LIKE '%John%'

WHERE Clause

The WHERE clause is used to filter the results of a SELECT statement based on specific conditions. It allows you to retrieve only the data that meets the criteria. For example: SELECT * FROM customers WHERE age >= 18

JOIN Statements

JOIN statements allow you to combine data from multiple tables based on common columns. Inner JOIN, Left JOIN, and Right JOIN are commonly used types of JOIN statements.


The GROUP BY clause groups data by one or more columns, while the HAVING clause filters the grouped data. These clauses are useful for summarizing and aggregating data.

Introduction to GraphQL

GraphQL is a relatively new query language designed for APIs. It allows you to request exactly the data you need from a server in a single request.

GraphQL Syntax

GraphQL uses a type system and a query language to define the structure and retrieval of data. It follows a schema-first approach where the data model is defined upfront.

GraphQL Schema

A GraphQL schema defines the types of data available and the operations that can be performed on them. It's a contract between the client and server that ensures data consistency.

GraphQL Queries and Mutations

GraphQL queries are used to retrieve data from a server, while mutations are used to create, update, or delete data. Both queries and mutations follow the defined schema.

Advantages of GraphQL

GraphQL offers several advantages over traditional REST APIs, including improved performance, flexibility, and a more efficient approach to data retrieval.

Next Up: Database Migration Tools (Knex.js, TypeORM)

In the next session, we'll explore Database Migration Tools. These tools help automate the process of changing the structure of a database over time, ensuring a seamless transition during database upgrades or schema modifications. Join us to learn how to use Knex.js and TypeORM for database migrations!