SQL: SELECT

SELECT (Output)


The SELECT command in SQL is a DQL (Data Query Language) command. Other DQL commands include: SHOW and HELP.


Example: display all fields for all records in the vehicles table


	SELECT * FROM vehicles;
	

Output:

make model color
Ford Mustang Blue
Ford F-150 Red

It should be noted that the word SELECT does not need to be capitalized, but this is a very common way to write SQL statements. It is done to differentiate the SQL keywords (e.g. SELECT, FROM, ORDER BY, INSERT, UPDATE, etc.) from non keywords (e.g. database table names, field names, etc.).


Example: display a particular field for all records in the employees table


	SELECT last_name FROM employees;
	

Output:

last_name
Williams
Smith
Jones

Example: display a particular field for all records in the employees table sorted by field


	SELECT last_name FROM employees ORDER BY last_name;
	

Output:

last_name
Jones
Smith
Williams