Introduction
We use selecting specific columns to get only the information we need from a table. This makes data easier to read and faster to get.
We use selecting specific columns to get only the information we need from a table. This makes data easier to read and faster to get.
SELECT column1, column2, ... FROM table_name;
SELECT name, email FROM users;
SELECT product_name, price FROM products;
SELECT date, sales FROM sales_data;
This creates a table called employees, adds three rows, and then selects only the name and department columns.
CREATE TABLE employees ( id INT, name VARCHAR(50), department VARCHAR(50), salary INT ); INSERT INTO employees (id, name, department, salary) VALUES (1, 'Alice', 'HR', 50000), (2, 'Bob', 'IT', 60000), (3, 'Charlie', 'Finance', 55000); SELECT name, department FROM employees;
If you want all columns, use SELECT * but it can be slower and harder to read.
Column names must be exact and match the table.
Selecting specific columns helps you get only the data you need.
Use commas to list columns after SELECT.
This makes queries faster and results clearer.
SELECT name, age FROM users; do?name and age, so only these will be retrieved.id and email from a table named customers?SELECT id, email FROM customers;.products with columns product_id, name, and price, what will be the output of this query?SELECT name, price FROM products WHERE price > 100;
name and price columns.price > 100.SELECT id name FROM employees;
id and name are missing a comma.employees and SELECT keyword are correct.orders with columns order_id, customer_id, order_date, and total. You want to get only the order_id and total for orders placed in 2023. Which query is correct?order_id and total only, so SELECT order_id, total is correct.WHERE YEAR(order_date) = 2023 correctly filters orders placed in 2023.Pass the test and this pattern moves unknown