subscribe: Posts | Comments

Selected Tables I


The selection of all or part of a table is done using the Select. In that election must specify:

-The fields that we want to select
-The table that make the selection

In our table model client could make such a selection of names and addresses of customers with an instruction like this:

Select Name, Address From Customers

If we want to select all fields, ie, the entire table, we could use the * wildcard as follows:

Select * From Customers

It is also useful to filter the records by the conditions that are expressed after the WHERE clause. If we want to show the customers of a particular city would use an expression like this:

Select * From Customers where City Like ‘Madrid’

We may also sort the results based on one or more of its fields. For example the latter could sort by name as follows:

Select * From Customers where City Like ‘Madrid’ ORDER BY name

Given that there may be more than one client with the same name, could provide a second criterion could be the surname:

Select * From Customers where City Like ‘Madrid’ ORDER BY name, surname

If the order invirtiésemos’ name, last name "with" full name ", result & iacutea be different. We ordered the customers by name and those who have identical names subclasificarían by name.

You may also sort by the reverse order. If for example we want to see our clients in order of taking orders for the largest first write something like this:

Select * From Customers Order By Desc orders

An interesting option is to make selections without coincidence. If for example the buscásemos know what cities are our clients without the need for it appears that several times the city would use a sentence of this class:

Select Distinct From Customers Order By population population

So avoid seeing Madrid repeated as many times as customers have in this population.