Problem Description
Given a table named students with columns student_id, name, and age, write a SQL query to select the name and age of the student whose student_id is 101.
Key Insights
- The query only requires two columns: name and age.
- A condition (WHERE clause) is used to filter records by student_id.
- This is a straightforward SELECT query with a simple filtering condition.
Space and Time Complexity
Time Complexity: O(1) – The query retrieves a specific row using a filtering condition, assuming an indexed student_id. Space Complexity: O(1) – Only a fixed amount of data (two columns for one row) is returned.
Solution
The solution uses a basic SQL SELECT statement with a WHERE clause. The WHERE clause ensures that only the row with student_id = 101 is selected. This is the simplest and most direct solution to the problem. The data structure involved is the relational table itself, and the algorithmic approach is simply filtering based on a condition.