My First SQL Queries

  • Jul 26, 2021
click fraud protection

The basic syntax of a select query is as follows:

  • SELECT Fields DESDE Table;

Where fields is the list of fields to be retrieved and table is their origin, for example:

Advertisements

  • SELECT Name, Telephone DESDE Customers;

This query returns a list with the name and phone field from the customers table.

Additionally, you can specify the order in which you want to retrieve the records from the tables using the clause ORDER BY List of Fields. Where Field List represents the fields to sort. Example:

Advertisements

  • SELECT Postal Code, Name, Telephone DESDE Customers ORDER BY Name;

This query returns the Postal Code, Name, Telephone fields from the Customers table ordered by the Name field.

Records can be sorted by more than one field, such as:

Advertisements

  • SELECT Postal Code, Name, Telephone DESDE Customers ORDER BY Postal Code, Name;

You can even specify the order of the records: ascending through the clause (ASC takes this default value) or descending (DESC)

  • SELECT Postal Code, Name, Telephone DESDE Customers ORDER BY Postal Code DESC , Name ASC;
instagram viewer