SQL Practice 1

SQL Practice – 1

If we want to retrieve all of the information about all of the customers in the Employees table, we could use the asterisk (*) as a shortcut for all of the columns, and our query looks like

 

Output:

SQLC1

If we want only specific columns (as is usually the case), we can/should explicitly specify them in a comma-separated list, as in

 

Output:

SQLC2

We want to select only the distinct values from the column named “deptno” from the emp table

 

Ouput:

SQLC3

We want to select only the employees whose working as “Manager” from the emp  table.

 

Ouput:

SQLC4

We could also use the NOT operator, to fetch those rows that are not  between the specified columns.

 

Ouput:

SQLC5

To get a list of employees who were hired on or after a given date, you would write like this

 

Ouput:

SQLC6

We wanted to see if the employees name is”FORD” and ” ALLEN”, we would write

 

Ouput:

SQLC7

This query retrieves data only from those rows of the emp table where the Comm is NULL.

 

Output:

SQLC8

To select employees  whose name begins with ‘S’

 

Output:

SQLC9

It is also possible to select the employees does NOT contain the pattern “S” from the “emp” table, by using the NOT keyword.

 

Ouput:

SQLC10

If you want to sort the emp table by the name, the query would be like,

 

Ouput:

SQLC11

By default, the ORDER BY Clause sorts data in ascending order. If you want to sort the data in descending order, you must explicitly specify it as shown below

 

Ouput:

SQLC12

If you want to sort the emp table by the sal+nvl(comm.,0), the query would be like,

 

Ouput:

SQLC13

NOTE:The columns specified in ORDER BY clause should be one of the columns selected in the SELECT column list.

You can represent the columns in the ORDER BY clause by specifying the position of a column in the SELECT list, instead of writing the column name.

The above query can also be written as given below,

 

Ouput:

SQLC14

Related posts:

Leave a Reply