The Ultimate Beginners Guide to learn SQL Programming: A Smart Step by Step Guide to Learn SQL Database and Server. How to Building an Advanced and Elite Level in SQL by Base Leonard

The Ultimate Beginners Guide to learn SQL Programming: A Smart Step by Step Guide to Learn SQL Database and Server. How to Building an Advanced and Elite Level in SQL by Base Leonard

Author:Base, Leonard [Base, Leonard]
Language: eng
Format: epub
Published: 2019-11-10T16:00:00+00:00


The "ORDER BY" clause can be utilized for specifying a list of columns to be sorted.

The "LIMIT" clause can be utilized for restricting the number of rows displayed upon execution of the command.

Note that only “SELECT” and “FROM” clauses are necessary to execute the command and all other clauses can be used on ad-hoc basis.

For instance, if you are interested in displaying only the "first name", "last name", and "job title" of all employees, you can utilize the syntax below:

"SELECT

lastname, firstname, jobtitle

FROM

employees;"

But if you would like to view all the columns in the “employees” table, use the syntax below:

"SELECT * FROM employees;"

In practice, it is recommended to list the columns you would like to view instead of using the asterisk (*) command, as the asterisk (*) will return all column data, some of which you may not be allowed to use. It will create “non-essential I/O disk and network traffic between the MySQL database server and the application”. If the columns are defined explicitly, then the "result set" becomes simpler to predict and handle. Suppose you are using the asterisk (*) and some other user modified the table and generated additional columns, you would receive a "result set" containing different columns than needed. Moreover, the use of asterisk (*) can potentially reveal sensitive data to unauthorized users.

MySQL SELECT DISTINCT

You can receive duplicate rows when searching for information from a table. You could utilizee the "DISTINCT" clause in the "SELECT" query to get rid of these redundant rows.

The "DISTINCT" clause syntax is given below:

"SELECT DISTINCT

columns

FROM

table_name

WHERE

where_conditions;"

EXAMPLE

The syntax below presents an example for the "DISTINCT" clause, used to selectively view “unique last names” of the employees from the "employees" table.

First, you need to display the “last names” of all employees from the “employees” tables using the syntax below:

"SELECT

last name

FROM

employees

ORDER BY last name;"

Now to get rid of the repeated last names, use the syntax below:

"SELECT DISTINCT

last name

FROM

employees

ORDER BY last name;"

Please note, if a column has been indicated to hold “NULL” values and the “DISTINCT” clause is used. Only one “NULL” value will be retained by the sever since the “DISTINCT” clause will consider all “NULL” values as identical.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.