SQL Data Query Language Statements
In this chapter you will learn how to use the available Data Query Language statements in retrieving data from database tables. Through SQLiteStudio, you will be able to use SELECT, WHERE, ORDER BY and GROUP BY statements in requesting and displaying significant database information.
Once you have created and populated your tables with data values, there will come a time that you will need to perform database queries to retrieve relevant information. A query is a valid inquiry into the database to extract and display data in a readable or understandable format, depending on the user’s request. The main challenge in SQL is to correctly instruct the computer what to search for by manipulating the database through row selection. Once you have selected the values you need then you can further perform various operations such as data addition, deletion, modification and more.
Using the SELECT statement in retrieving all the records of a particular table is the basic form of this DML command statement. Even if the SELECT command is considered to be the most powerful statement, it requires other clauses to function correctly in performing a query. The syntax in its simplest form is:
SELECT * FROM TABLE_NAME;
In the programming line above, the asterisk sign (*) signifies everything. This means that the wildcard character is a shortcut for the listing of all the column names of a particular table.
To select all the data rows from the Customer_TBL table:
SELECT COLUMN_LIST
FROMTABLE_NAME WHERECONDITION;
To select only the rows of data where the job position of the customer is Vice-President:
What if you only want to select certain columns of the table, maybe just the full name and company of the customer? You will now modify your lines of code into the following:
Once you have created and populated your tables with data values, there will come a time that you will need to perform database queries to retrieve relevant information. A query is a valid inquiry into the database to extract and display data in a readable or understandable format, depending on the user’s request. The main challenge in SQL is to correctly instruct the computer what to search for by manipulating the database through row selection. Once you have selected the values you need then you can further perform various operations such as data addition, deletion, modification and more.
SELECT Statement
Retrieving data values is the most performed manipulation task by database users. In doing such operation you need to use the DML command statement called SELECT. You have the option to retrieve just one row, a number of rows or all the rows of the database table.Using the SELECT statement in retrieving all the records of a particular table is the basic form of this DML command statement. Even if the SELECT command is considered to be the most powerful statement, it requires other clauses to function correctly in performing a query. The syntax in its simplest form is:
SELECT * FROM TABLE_NAME;
In the programming line above, the asterisk sign (*) signifies everything. This means that the wildcard character is a shortcut for the listing of all the column names of a particular table.
To select all the data rows from the Customer_TBL table:
- Click the SQL Editor option and then type the following lines of code:
SELECT * FROM Customer_TBL; - Click the EXECUTE QUERY button displayed inside the GRID VIEW tab.
WHERE Statement
When you want to be more specific in selecting rows of data from your database tables then you need to add a bit of complexity to your programming lines. At this point, you need the function of the WHERE clause, which means that the SELECT operation will be performed once the stated condition inside such clause is true. The syntax of the SELECT statement with the WHERE clause is as follows:SELECT COLUMN_LIST
FROMTABLE_NAME WHERECONDITION;
To select only the rows of data where the job position of the customer is Vice-President:
- Click the option and then type the following lines of code:
- Click the EXECUTE QUERY button displayed inside the GRID VIEW tab.
SELECT *
FROM Customer_TBL
WHERE JobPosition = ‘Vice-President’;
What if you only want to select certain columns of the table, maybe just the full name and company of the customer? You will now modify your lines of code into the following:
- In the QUERY tab, change the wildcard character * (asterisk sign) into CustomerName and CompanyName by typing the following:
- Click the EXECUTE QUERY button displayed inside the GRID VIEW tab.
SELECT CustomerName, CompanyName
FROM Customer_TBL
WHERE JobPosition = ‘Vice-President’;
No comments