Learn MQL with Real Code Examples
Updated Nov 18, 2025
Code Sample Descriptions
1
Basic MQL Queries
// Find users aged over 25
db.users.find({ age: { $gt: 25 } })
// Find users, only return name and email
db.users.find({}, { name: 1, email: 1 })
// Aggregation: group by status and count
db.orders.aggregate([
{ $group: { _id: "$status", total: { $sum: 1 } } }
])
Examples of finding documents, projecting fields, and using aggregation in MongoDB.
2
Basic SQL Queries
-- Select all users
SELECT * FROM users;
-- Select specific columns
SELECT name, email FROM users;
-- Select with filter
SELECT * FROM users WHERE age > 25;
-- Order results
SELECT * FROM users ORDER BY created_at DESC;
Simple SQL operations: SELECT, WHERE, ORDER BY.
3
PostgreSQL Joins
-- Inner Join
SELECT u.name, o.id
FROM users u
INNER JOIN orders o ON u.id = o.user_id;
-- Left Join
SELECT u.name, o.id
FROM users u
LEFT JOIN orders o ON u.id = o.user_id;
-- Right Join
SELECT u.name, o.id
FROM users u
RIGHT JOIN orders o ON u.id = o.user_id;
Examples of INNER JOIN, LEFT JOIN, and RIGHT JOIN in PostgreSQL.
4
Redis Basics
# Set and Get
SET user:1 "Alice"
GET user:1
# Hash operations
HSET user:2 name "Bob" age 30
HGETALL user:2
# List operations
LPUSH tasks "task1" "task2"
LRANGE tasks 0 -1
Basic Redis key-value operations.
5
MySQL Aggregations
-- Count users
SELECT COUNT(*) FROM users;
-- Average age
SELECT AVG(age) FROM users;
-- Total orders
SELECT SUM(amount) FROM orders;
Aggregations like COUNT, AVG, SUM in MySQL.
6
SQLite Table Creation
-- Create table
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT,
email TEXT
);
-- Insert row
INSERT INTO users (name, email) VALUES ('Alice', 'alice@mail.com');
-- Query
SELECT * FROM users;
Creating tables and inserting rows in SQLite.
7
Cassandra CQL Queries
-- Create keyspace
CREATE KEYSPACE shop WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
-- Use keyspace
USE shop;
-- Create table
CREATE TABLE users (id UUID PRIMARY KEY, name TEXT, age INT);
-- Insert
INSERT INTO users (id, name, age) VALUES (uuid(), 'Alice', 29);
-- Select
SELECT * FROM users;
Basic CQL queries for Cassandra.
8
Neo4j Cypher Basics
// 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;
Basic graph queries using Cypher in Neo4j.
9
Elasticsearch DSL Queries
{
"query": {
"bool": {
"must": [
{ "match": {title: "database" } },
{ "range": { "year": { "gte": 2020 } } }
]
}
}
}
JSON-based query DSL examples in Elasticsearch.
10
InfluxDB Time-Series Queries
-- Create measurement
INSERT temperature,location=room1 value=23.5
-- Select with time filter
SELECT value FROM temperature WHERE time > now() - 1h;
-- Aggregate
SELECT MEAN(value) FROM temperature WHERE time > now() - 24h GROUP BY time(1h);
InfluxQL examples for querying time-series data.