Code / SQL with Data / Unit 1: Tables and SELECT

Your first query आपकी पहली क्वेरी

Lesson 1 of 13 · about 12 minutes · What a table is, SELECT * and picking columns.

⚡ 0 XP

Step 1 of 2

Databases and tables

TeamPPtsMI1418CSK1416RCB1414

A database is an organised store of data. Inside it, data lives in tables, just like sheets in Excel.

  • Each row is one thing: one player, one sale, one train
  • Each column is one fact about it: name, team, runs

Our first table is players: made-up cricketers with their matches, runs and wickets. It is sample data for practice, not official statistics. Look at the Tables panel to see its columns and how many rows it has.

You talk to a database in SQL (say “sequel” or “S-Q-L”). The most important command is SELECT. This query shows everything:

SELECT * FROM players;

* means “all columns”, FROM players says which table. The ; ends the statement. SQL keywords are not case-sensitive, but writing them in CAPITALS makes queries easy to read.

Example
-- Sample data for practice,
-- not official statistics.
SELECT * FROM players;

Press Run: you get a grid with all 15 players.

🎯 Challenge: Meet the players +10 XP

Show every column and every row of the players table.

Try twice to unlock the solution (0/2)

query.sqlCtrl ⏎
…
Checklist

Press Run to check your code.

  • Your rows match the expected answer
  • All 15 rows are shown
  • Uses FROM players
Lesson notes (text version)

1. Databases and tables

A database is an organised store of data. Inside it, data lives in tables, just like sheets in Excel.

  • Each row is one thing: one player, one sale, one train
  • Each column is one fact about it: name, team, runs

Our first table is players: made-up cricketers with their matches, runs and wickets. It is sample data for practice, not official statistics. Look at the Tables panel to see its columns and how many rows it has.

You talk to a database in SQL (say “sequel” or “S-Q-L”). The most important command is SELECT. This query shows everything:

SELECT * FROM players;

* means “all columns”, FROM players says which table. The ; ends the statement. SQL keywords are not case-sensitive, but writing them in CAPITALS makes queries easy to read.

                -- Sample data for practice,
-- not official statistics.
SELECT * FROM players;
              

Challenge: Meet the players

Show every column and every row of the players table.

2. Pick the columns you need

Real tables can have 50 columns. Usually you want only a few. Instead of *, list the columns you want, separated by commas:

SELECT name, team FROM players;

The result shows the columns in the order you wrote them. Column names must be spelled exactly as in the Tables panel — run instead of runs gives an error.

                SELECT name, team FROM players;
              

Challenge: Just names and runs

Show only two columns from players: name and then runs, for all players.

Search by task, format or tool name.