Have you worked with databases? Can you give an example of a JOIN query? What is the purpose of HAVING? Where is DISTINCT used? What filtering operations do you know? How does LIKE work? What types of databases do you know? What is the purpose of primary and foreign keys?
sobes.tech AI
Answer from AI
Yes, I have worked with databases and can provide examples and explanations for your questions.
Example of a JOIN query:
SELECT users.name, orders.amount
FROM users
JOIN orders ON users.id = orders.user_id;
This query joins the users and orders tables on the user_id field.
HAVING is used to filter groups after aggregation, for example:
SELECT user_id, COUNT(*) as orders_count
FROM orders
GROUP BY user_id
HAVING COUNT(*) > 5;
This selects users with more than 5 orders.
DISTINCT is used to select unique values and is written after SELECT:
SELECT DISTINCT country FROM users;
This returns a list of unique countries.
Filtering operations:
- WHERE — filters rows before grouping
- HAVING — filters groups after aggregation
- LIKE — pattern matching
- IN — checks for inclusion in a set of values
- BETWEEN — range of values
LIKE is used for pattern matching with wildcards:
%— any number of any characters_— a single any character
Example:
SELECT * FROM users WHERE name LIKE 'A%';
Finds names starting with 'A'.
Types of databases:
- Relational (PostgreSQL, MySQL, Oracle)
- Document-oriented (MongoDB)
- Key-value (Redis)
- Columnar (ClickHouse)
- Graph (Neo4j)
Primary key (PRIMARY KEY) — a unique identifier for a row in a table, guarantees uniqueness and is indexed.
Foreign key (FOREIGN KEY) — a field that references the primary key of another table, ensures data integrity and relationships between tables.