Data Analyst Interview
Menu
Browse in your language. All mock interviews, preparation sessions and feedback are in English only.

SQL vs NoSQL: Data Models and Order Examples

Databases · Interview foundations

SQL vs NoSQL: Explain the Difference with an Order Example

Compare a relational order model with a document model, then explain the trade-offs without repeating database myths.

By Prakhar Shrivastava · Published 15 September 2026 · Practical learning guide

Describe the model before the slogan

SQL is a query language. In an interview, “SQL database” usually refers to a relational database that organises information into tables. NoSQL describes several families of databases, including document, key-value, graph and wide-column systems. It is not one alternative with one fixed set of capabilities. See MongoDB’s overview of NoSQL models.

A useful answer starts with how the application reads and changes data. Suppose a shop needs order history for one customer and a monthly revenue report by city. Those two requests suggest different access patterns. Neither the file extension nor the number of records alone determines the best database.

Model orders in related tables

In this invented example, the customer table has one row per customer. The order table has one row per order and refers to the customer by ID. Run the following self-contained query in SQLite or PostgreSQL.

WITH customers(customer_id, city) AS (
    VALUES (1, 'Pune'), (2, 'Delhi'), (3, 'Pune')
), orders(order_id, customer_id, amount) AS (
    VALUES (101, 1, 500), (102, 1, 300), (103, 2, 700)
)
SELECT c.city, SUM(o.amount) AS revenue
FROM orders AS o
JOIN customers AS c ON c.customer_id = o.customer_id
GROUP BY c.city
ORDER BY c.city;
cityrevenue
Delhi700
Pune800

Customer 3 has no orders and contributes no revenue. The inner join includes only matching records. If an order referred to a missing customer, this query would omit it. That is why the relationship and missing-match checks belong in your explanation.

In permanent relational tables, a primary key can enforce customer-ID uniqueness and a foreign key can enforce the reference. A join combines rows for a query; declaring a foreign key is a separate integrity rule. Read the PostgreSQL guides to joins and foreign keys. The tiny CTE example above defines neither constraint.

Represent an order as a document

A document model could store an order together with its delivery-address snapshot and items. This illustrative JSON is a data shape, not a database command:

{
  "order_id": 101,
  "customer_id": 1,
  "delivery_city_at_order": "Pune",
  "items": [{"sku": "BOOK-A", "quantity": 1, "amount": 500}]
}

Reading one order can return its associated items. The address snapshot answers where the order was delivered, even if the customer moves later. By contrast, joining to a customer table containing only the current city answers a different question. A disagreement between the two reports may be a definition issue rather than a database bug.

Documents can embed related values or reference other documents. Repeating a value may make a particular read simpler but adds decisions about updates and consistency. MongoDB’s data-modelling guidance discusses designing around the application’s access patterns.

Ask questions that change the choice

QuestionWhy it matters
Do we report by current city or historical delivery city?The required history changes the model
Which values must change together?Transaction and consistency requirements need explicit design
Do reports combine many entities?Analytical joins and aggregation access matter
Which queries are slow on realistic data?Indexes, layout and workload need measurement
Who maintains the system?Operational experience is part of the decision

Avoid claims that NoSQL has no schema, that relational databases cannot scale horizontally, or that every NoSQL system sacrifices transactions. Capabilities depend on the product and configuration. Flexible records still need a defined meaning; otherwise one document may use US dollars while another stores US cents under the same field name.

For an analyst, also ask how operational data reaches the reporting environment. The application may use a document database while the analytics team queries a relational warehouse. Learn the source model so you can recognise repeated arrays, missing fields and changes in record structure.

Practise a concise interview answer

“Relational modelling separates entities into tables with explicit relationships. A document model can keep values that are read together in one record. I would choose based on access patterns, integrity requirements and operational constraints. For this shop, I would first define whether city means the customer’s current address or the delivery address at purchase.”

Now change the example so one order contains three items. Explain whether your result is one row per order or per item before summing anything. That small change is a common source of duplicated revenue. Practise the relevant joins in the SQL learning hub.

✉ WhatsApp