The SELECT statement

When using SQL in website development, you will find that this is the statement you will use most. To put it simply, the 'SELECT' statement will retrieve data from a database. From then on, you choose how you want to display it. Whether it be in an HTML table, dropdown menu, etc. You may also choose to store the data in an array for later use.

The Syntax

SELECT column1,column2 FROM database WHERE column1='text'

'SELECT' is the keyword here. This tells the server to take or collect the data. But this is not enough. The server needs to know what database and what data. So we define the data as the column names. If you want all the data, simply replace the column names with an asterisk (*). The server still needs to know which database we are looking in. Therefore we add 'FROM database'. This is your basic structure for the SELECT statement.

Real life example

So now we'll look at a real life example so that you can see how the statement works and perhaps relate it to a database of your own.

SELECT username,password FROM users

This is a very common example of using the SELECT statement. You will find this on any website which uses a membership system. It will be used for various functions.

  1. To display a user's profile.
  2. To check whether the username already exists upon registration.
  3. To check the username and password combination exists on login.