0
0
MySQLquery~5 mins

Selecting specific columns in MySQL

Choose your learning style9 modes available
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.

When you want to see only names and emails from a list of users.
When you need to check prices of products without extra details.
When you want to show a report with just dates and sales numbers.
When you want to avoid loading large amounts of unnecessary data.
When you want to focus on a few important details in a big table.
Syntax
MySQL
SELECT column1, column2, ... FROM table_name;
List the columns you want separated by commas.
Use the table name after FROM to tell where to get data.
Examples
This gets only the name and email columns from the users table.
MySQL
SELECT name, email FROM users;
This shows product names and their prices from the products table.
MySQL
SELECT product_name, price FROM products;
This selects just the date and sales columns from sales_data.
MySQL
SELECT date, sales FROM sales_data;
Sample Program

This creates a table called employees, adds three rows, and then selects only the name and department columns.

MySQL
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;
OutputSuccess
Important Notes

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.

Summary

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.