Learn CQL with Real Code Examples
Updated Nov 18, 2025
Code Sample Descriptions
1
Basic CQL Queries
CREATE TABLE users (
id UUID PRIMARY KEY,
name TEXT,
age INT
);
INSERT INTO users (id, name, age)
VALUES (uuid(), 'Alice', 30);
SELECT name, age FROM users
WHERE age > 25;
Examples of creating a table, inserting data, and querying in Cassandra using CQL.
2
MySQL Select Queries
-- Select all rows
SELECT * FROM employees;
-- Select with condition
SELECT name, salary FROM employees WHERE salary > 50000;
-- Sort results
SELECT * FROM employees ORDER BY hire_date DESC;
Basic MySQL queries for selecting rows with filters and sorting.
3
PostgreSQL Table and Insert
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
price NUMERIC
);
INSERT INTO products (name, price)
VALUES ('Laptop', 1200.50),
('Phone', 699.99);
SELECT * FROM products;
Creating a table and inserting rows in PostgreSQL.
4
MongoDB Basic Operations
// Find all users
db.users.find({})
// Find by condition
db.users.find({ age: { $gte: 21 } })
// Aggregation: group by role
db.users.aggregate([
{ $group: { _id: "$role", total: { $sum: 1 } } }
])
Examples of find, projection, and aggregation in MongoDB.
5
SQLite Create and Query
CREATE TABLE books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT,
author TEXT
);
INSERT INTO books (title, author)
VALUES ('1984', 'George Orwell');
SELECT * FROM books;
Creating a table, inserting values, and running queries in SQLite.
6
Redis Commands
# Set and Get
SET session:1 "active"
GET session:1
# Hash example
HSET user:1 name "Alice" age "30"
HGETALL user:1
# List example
LPUSH queue task1 task2
LRANGE queue 0 -1
Common Redis commands for strings, hashes, and lists.
7
Neo4j Cypher Queries
// Create nodes
CREATE (a:Person {name: "Alice"}), (b:Person {name: "Bob"});
// Create relationship
MATCH (a:Person {name: "Alice"}), (b:Person {name: "Bob"})
CREATE (a)-[:FRIEND]->(b);
// Query
MATCH (p:Person)-[:FRIEND]->(f)
RETURN p.name, f.name;
Creating nodes, relationships, and querying with Cypher in Neo4j.
8
Elasticsearch Query DSL
{
"query": {
"match": {
title: "database"
}
}
}
{
"query": {
"range": {
"year": { "gte": 2020 }
}
}
}
Performing search queries using Elasticsearch Query DSL.
9
InfluxDB Time-Series Queries
-- Insert temperature reading
INSERT temperature,location=room1 value=24.5
-- Query last hour
SELECT value FROM temperature WHERE time > now() - 1h;
-- Group by 5 minutes
SELECT MEAN(value) FROM temperature
WHERE time > now() - 1d GROUP BY time(5m);
Using InfluxQL for inserting and querying time-series data.
10
Oracle PL/SQL Block
DECLARE
v_name VARCHAR2(50) := 'Alice';
v_age NUMBER := 30;
BEGIN
DBMS_OUTPUT.PUT_LINE('Name: ' || v_name || ', Age: ' || v_age);
END;
Example of a PL/SQL block with variable declaration and output.