Learn how to select only specific columns from a SQL table using the SELECT clause with a clear example for better performance and readability.
-- Select only the columns first_name, last_name, and email from the users table
SELECT nome, cognome, email
FROM utenti;-- Create a sample table named 'utenti'
CREATE TABLE utenti (
nome VARCHAR(50),
cognome VARCHAR(50),
email VARCHAR(100),
eta INT
);
-- Insert sample data into the 'utenti' table
INSERT INTO utenti (nome, cognome, email, eta) VALUES
('John', 'Doe', 'john.doe@example.com', 30),
('Jane', 'Smith', 'jane.smith@example.com', 25);
-- Select only the columns first_name, last_name, and email from the users table
SELECT nome, cognome, email
FROM utenti;Example table: users (id INT, first_name VARCHAR, last_name VARCHAR, email VARCHAR, age INT)
DEPENDENCIES: SQL database (e.g., MySQL, PostgreSQL, SQLite)
CONFIG: no special configuration required