Basic Data Retrieval
The SELECT statement is used to fetch data from a database. This query retrieves two specific columns: first_name and last_name from the employees table.
SELECT first_name, last_nameFROM employees;
Hand-picked snippets across TypeScript, Python, Rust, Go, and more — each one comes with a line-by-line breakdown so you can read it like the people who wrote it.
The SELECT statement is used to fetch data from a database. This query retrieves two specific columns: first_name and last_name from the employees table.
SELECT first_name, last_nameFROM employees;
The CREATE TABLE statement is used to create a new table in a database. You must define the name of the columns and their data types.
CREATE TABLE users (id INTEGER,username VARCHAR(50));
The ORDER BY keyword is used to sort the result-set in ascending (ASC) or descending (DESC) order. Here, products are sorted from most expensive to cheapest.
SELECT product_name, priceFROM productsORDER BY price DESC;
The WHERE clause is used to filter records. It ensures that only rows meeting a specific condition—in this case, products with a price greater than 100—are returned.
SELECT *FROM productsWHERE price > 100;
The COUNT() function returns the number of rows that matches a specified criterion. Using (*) counts all rows in the orders table.
SELECT COUNT(*)FROM orders;
The UPDATE statement is used to modify the existing records in a table. It is crucial to use a WHERE clause to specify which record(s) should be updated; otherwise, all records in the table will be changed.
UPDATE employeesSET salary = 5500WHERE employee_id = 101;
INNER JOIN combines rows from two tables whenever there is a matching value in a common column. This allows you to retrieve data distributed across multiple tables in a single result set.
SELECT orders.order_id, customers.nameFROM ordersINNER JOIN customers ON orders.customer_id = customers.id;
Aliases are used to give a table or a column in a table a temporary name. They are often used to make column names more readable or descriptive in the output.
SELECT product_name AS item, unit_price AS priceFROM inventory;