Share via:

Simple SELECT Statements in SQL

How to perform simple SELECT statements in SQL to communicate with SQL databases.


Edited: 2019-09-11 16:44

SQL SELECT statements

SQL SELECT statements are used to return data from database tables. Most RDBMS uses SQL (Structured Query Language) to allow for easy communication with databases.

A simple SELECT is performed either by choosing which fields you want returned or by using the asterisk (*) wildcard to return everything. Using the asterisk may be fine for testing and niche-situations, but only selecting the fields you actually need will often improve performance.

SELECT * FROM table_name;

Using a WHERE clause allows us to only return specific results:

SELECT * FROM users_table WHERE email= '';

SQL SELECT statements

To return a specific row, you can use the WHERE clause. Depending on which field you use it on, you might end up selecting a single row or multiple rows. If you use WHERE on a unique field, such as a username, then you should only get a single row.

A SELECT is typically performed by deciding which fields you want returned from the database, this may look like this:

SELECT username, password_hash, email FROM users_table WHERE username = 'Jacob';

If this statement is entered in a command line, you might get a result like:

| username | password_hash | email            |
| Jacob    | ...           | |
1 row in set (0.00 sec)

You can also use asterisk (*) wildcard to select all fields in a database table, this is done like so:

SELECT * FROM table_name;

Performing a wildcard SELECT with a WHERE clause:

SELECT * FROM users_table WHERE username = 'Jacob';


Avoid using the "*" Asterix in your SQL select queries to speed up your selects. Only select the fields you actually need.

Using indexes in your table will significantly speed up your selects.