SELECT
SELECT is the single most common SQL command it's how you read data back out of a table. SELECT * FROM students; returns every column and every row from students. The * means "all columns." This is useful for exploring, but in real applications it's often better to ask for exactly what you need. SELECT name, age FROM students; returns only those two columns, for every row. Naming exactly the columns you need is generally better practice than * in real code: it's clearer to read, and it avoids pulling data your application doesn't actually use. You can also select values calculated on the fly, not just raw columns: SELECT name, age + 1 AS next_year_age FROM students; computes a new value per row without changing any stored data the table itself is untouched.
Why this matters
- ·SELECT lets you ask precise questions about your data instead of reading through every row manually.
- ·Naming exact columns keeps results focused and avoids pulling unnecessary data.
- ·You can compute new values on the fly in a SELECT without ever changing what's actually stored.
Common mistakes
- ·SELECT * on a huge table can return far more data than you actually need, slowing things down.
- ·Assuming column order in SELECT * results (instead of referring to columns by name) can break silently if the table changes.
- ·A SELECT with no WHERE clause returns every row in the table sometimes far more than intended.
+------+-----+ | name | age | +------+-----+ | Ali | 16 | | Sara | 17 | +------+-----+ 2 rows in set
PHP runs on a server, not in the browser this shows the expected output instead of a live one.
Frequently asked questions
It returns every column in the table, for every matching row.
Practice questions
Question 1
Write a SELECT that returns every column from the students table.
PHP runs on a server, not in the browser this shows the expected output instead of a live one.
Question 2
Write a SELECT that returns only the name column from students.
PHP runs on a server, not in the browser this shows the expected output instead of a live one.
Quick check
Just for this topic answer honestly, then check yourself.
1 / 3
