SQL For Beginners (Part1): Select

Tram Ho

This is the first article in the SQL For Beginners series. In this article, we will learn about the common types of SELECT queries

1. Setup

The examples in this article use the following tables. (You can execute the queries in the lesson with the free SQL Fiddle online tool)

2. Wildcard *

The * character is a wildcard. Using this select method is similar to the “bring us all visible columns in the table” request.

In the above example, when we ran the query, all data for all columns were displayed. Wildcard characters can also be used in select statements with multiple tables. In the example below we have 2 tables joined together, and we will query all the columns in both tables.

3. Columns

In many cases, it is not necessary to select all the columns in the table, but only to retrieve a few specific columns, in which case we can select by the column name.

4. Alias

  1. Column AliasWe can change the names of the returned columns (change the return value, not the table structure) through alias. For example below we have 2 aliase. The first one is not case-sensitive, while the second one uses double-quote, to force case-sensitive display of the column name as desired.

  1. Table AliasTable aliase improves the readability and comprehension of the query as the query complexity increases (join, subquery …). In the next example, we have ‘e’ as alias for the employees table and ‘d’ as alias for departments.

5. Functions

The select list may also include functions (be it buil-in functions or PL / SQL functions that you define yourself). The following example uses the UPPER function to turn a string containing lower case text into upper case text.

Oracle provides quite a lot of build-in functions. Refer to Oracle built-in function list

6. Expressions

Expressions can also be listed in the select list, including mathematical expressions.

7. Scalar Subqueries

Scalar subqueries are subqueries that return only one record and that record includes only one column. Scalar subquery can also be listed in the select list as in the example below.

Reference source: https://oracle-base.com/articles/misc/sql-for-beginners-the-select-list

Share the news now

Source : Viblo