Thursday, October 12, 2017

Select and Display data from Table using SQL

Database administrator can query and display data from table directly using SQL statements. The most basic SQL query to retrieve and display information from table on to computer screen is the SELECT statements. This lab will use the tables created in Lab 2 and the insert table steps to demonstrates the use of SELECT query.

SELECT Data from Table
Select and display all data can be done by using the following syntax:
The example in Figure 1 below shows how the SQL statement is used to retrieve and display the data in table "students".
Figure 1: Retrieve and display all data from table "students"

SELECT Data a set of Column in Table
User can choose to select and display a particular set column of data to be shown to the screen. The operation can be done using the SQL syntax below.
The example in Figure 2 below shows how the SQL statement is used to select and display only the student name column and the year of intake column in the table "students".
Figure 2: Select and display only 2 column from table "students".
WHERE clause in SELECT Statements:
Specifying the column name in the SELECT statements can help to filter out the unwanted column in the data retrieve and display. How about filtering the data in row? The WHERE clause is use together with SELECT statements to filter out specific information in the database to be shown to the user. the syntax of WHERE in SELECT statements is shown below:
Figure 3 below shows how to select the data for a student called "Enson Liu" from the table "students":
Figure 3: Select data for student called "Enson Liu".
Notice in Figure 3, where the result only display the data for student named "Enson Liu", while the select statement in Figure 1 shows data for 2 students.