Learn with Abdou

INTERACTIVE LECTURES

Understand database structure

Guided class activity · apply the ideas from the full SQL lessons.

Opening your saved work…

Sign in to save across devices → · Download your guest work before switching accounts.

Identify entities and keys

Step 1 of 3 · Database: Northshore Coffee

READ & UNDERSTAND

A table groups facts about a type of entity or event. In this database one shops row represents a shop, one employees row an employee, and one orders row an order.

A primary key identifies a row. A name is often a poor key because names can repeat or change. Keep the identifier and the human-readable label separate.

An ERD should label the entities, keys, and relationship cardinalities. The database explorer shows declared keys; business rules require explanation beyond the diagram.

Worked example
SELECT id, name, city FROM shops ORDER BY id;

The shop id is the stable row identifier, while name and city make the result understandable. Several shops can share a city without representing the same shop.

The employee exercise deliberately includes shop_id beside employee id. Identifiers with the same numeric value are not interchangeable when they refer to different tables.

Your question

Return id, first_name, last_name, and shop_id for the first five employees ordered by id.

Explain your evidence

Which field identifies the employee? Which connects that employee to a shop?

Try a query to unlock the worked-answer discussion.

Loading…
Table & column names only · ↑ ↓ choose · Tab insert · Esc dismiss

CURRENT DATABASE

Quick schema · Northshore Coffee

Press Esc or click outside to return to your query. PK = primary key · FK = declared foreign key.

This database has no tables yet. Create a table, then reopen the schema to see its columns.

Control Space also opens names. Enter adds a new line. Control or Command Enter runs your query.

Query results

Predict the result, then run your query.

Predict the result, then run your query.

Read-only activity · One statement per run · First 200 rows displayed · Checks compare the complete bounded result, not just this preview.

Explore this query freely in the playground ↗

Check the save status above. Account-saved work is available in My Progress. Explanations are for discussion, not automatically graded. No prerequisite locks.