Structured Query Language (SQL)
Inserting and selecting data
Write INSERT statements and simple SELECT queries.
Adding data:
- INSERT INTO table VALUES (value1, value2, ...); gives a value for every column, in order.
- INSERT INTO table (column1, column2) VALUES (value1, value2); fills only the named columns.
Text and dates go inside single quotes: 'Atharv', '2025-04-12'. Records must be inserted into a referenced table (such as GUARDIAN) before the table that refers to it (STUDENT), or the foreign key will have nothing to point to.
Asking questions: the SELECT statement retrieves data:
SELECT column1, column2 FROM table WHERE condition;
- SELECT * FROM table; shows all the columns.
- AS gives a column a new name in the output only; the table itself does not change. For example, SELECT Ename, Salary * 12 AS 'Annual Income' FROM EMPLOYEE;
- DISTINCT removes repeated values from the output: SELECT DISTINCT DeptId FROM EMPLOYEE; lists each department just once.
- WHERE picks out rows that meet a condition, using comparison operators (=, <, >, <=, >=, != or <>) and logical operators (AND, OR, NOT).
INSERT adds data; SELECT asks questions of it.
Practise this lesson
Questions that get harder as you improve, a Tutor that helps without giving the answer away, and progress you can see. Free for every learner.
No account, no email address. Opens the real product.