Sql Select From
An sql select statement returns a set of data records from one or more data tables.
In this sql select tutorial we will use the sample table below for our sql select statement examples.
Our table sample is an ordinary users table that stores user's informations basically.
Users Table; tbl_users
| id | Name | Password | Age | |
|---|---|---|---|---|
| 1 | John Doe | johndoe@j.com | e56Hdf-2 | 34 |
| 2 | Jane Doe | janedoe@j.com | p59Hdf-2 | 32 |
| 2 | Gary Doe | garydoe@j.com | y02Tdf-2 | 23 |
SQL Select Code
SELECT * FROM tbl_users
This sql query will return all the rows from users table.
Note that sql queries are not case sensitive.
Selecting specific columns from table
SELECT id,Name FROM tbl_users
In this sql query we only select id and user name from users table.
The result
| id | Name |
|---|---|
| 1 | John Doe |
| 2 | Jane Doe |
| 2 | Gary Doe |
SQL SELECT Optimization Tips
- Always limit your sql queries with using limit. This will increase your speed. Faster data transfer from database to your application.
- Use paging while selecting from tables with limit statement.
- Select only the columns you require in your application. Less memory space, and faster.
SQL SELECT Code Samples
- C# MS SQL Server SELECT
- C# MS Access SELECT
- Visual Basic MS SQL Server SELECT
- Visual Basic MS Access SELECT
- PHP MySQL Select Tutorial