quinta-feira, 5 de abril de 2018

sql select 2

abril 05, 2018 Posted by Unknown No comments

Selecting All Columns
MySQL

SELECT *
FROM ALUNO;
1
2
SELECT *
FROM ALUNO;

Selecting All Columns and All Rows
You can display all the columns of data in a table by placing an asterisk (*) just after the SELECT keyword. In the example above, the STUDENTS table has three columns: student_id, name, email, dtcadastro.

You can also display all the columns of the table by listing them after the SELECT keyword. For example, the following SQL command, as in the example above, also displays all columns and all rows in the STUDENT table:

MySQL

SELECT id_aluno, nome, email, dtcadastro
FROM aluno;
1
2
SELECT id_aluno, nome, email, dtcadastro
FROM aluno;
Selecting Specific Columns

MySQL

SELECT id_aluno, nome
FROM aluno;
1
2
SELECT id_aluno, nome
FROM aluno;

Selecting Specific Columns and All Rows
You can use the SELECT command to display specific columns of the table by specifying the column names, separated by commas. The above example displays all the ids and names of the student table.

In the SELECT clause, specify the columns you want to see, in the order in which you want them to be displayed. For example, to display the name before the student's id, you use the following command:

MySQL

SELECT id_aluno, nome
FROM aluno;
1
2
SELECT id_aluno, nome
FROM aluno;

Column Header Defaults
The behavior of select column headers depends on the manufacturer. Usually the header is the name of the column, but it can be uppercase, lowercase, centered, right-aligned, or left-aligned. It may still be truncated to column size or not. Character and date column headers can be truncated, while numeric column headers can not be truncated. You can replace column headers with an alias.

MySQL

SELECT nome
FROM aluno;
1
2
SELECT nome
FROM aluno;

Defining a Column Alias
To display the result of a query, SQL typically uses the name of the selected column as its header. In many cases, this title may not be descriptive and therefore may be difficult to understand. You can change the header of a column by using a column alias.

Specify the alias after the column in the SELECT clause list using the word 'AS'. The display default of the headers depends on the manufacturer of the database. If the alias has spaces, special characters (such as # or $), or should be case-sensitive, enclose the alias between double quotation marks ("").

0 comentários:

Postar um comentário