SELECT

The SELECT statement is used to obtain data from a database. The basic format of the SELECT INSTRUCTIONAL is that muetra below:

 SELECT FROM <campos> <table>

For example if you wanted to get the names and e-mail to all records from a database of personal agenda would use the following SQL INSTRUCTIONAL:

 SELECT surname, name, email FROM calendar

this command returns a recordset with data from the three fields listed (surname, name and email) of Table Book.
If you really want to get all the table fields you can use the following.

 SELECT * FROM Agenda

Although the use of the asterisk (*) is the most practical and fast to get all fields IS NOT A RECOMMENDED PRACTICE for two reasons and two Tiemen to do with the performance of the query.
a) do not ask all the fields in a table unless you need them all. There will always run faster if the query returns less data. The SELECT statement should request only the fields you will use.
b) if you need all the fields in the table as a result of the consultation, I recommend that you use the list of fields instead of the asterisk (*) and the reason is that if you tell the SQL engine which is the name fields will have to find it. For the developer this is transparent, but the engine is doing internally two queries: one to find out the names of the fields in the table and one for making the request that we ask.

ORDERING THE RESULTS

For the result to the database engine sends us reach a certain order using the ORDER BY clause, which is based on a list of fields to make the order.
Consider the same query from the beginning (the agenda) but ordered by last name:

 SELECT surname, name, email FROM book ORDER BY name, first name

by default the fields listed in the ORDER BY clause indicates an ascending sort, but if you want you can tell it down using the DESC keyword as shown below:

 SELECT surname, name, email FROM book ORDER BY name DESC, name

ascending order may also be indicated explicitly using the ASC keyword, but not necessary since the next instruction will result in the same order that the previous instruction must.

 SELECT surname, name, email FROM book ORDER BY name DESC, name ASC

11 Responses to "SELECT"

  1. [...] The following code and the name of the database. Mdb and the table name in the SELECT statement) so that everything works fine. Dim cnn As New [...]

  2. [...] To a particular instance of source code. See also: GROUP, HAVING, ISA, REFERENCES OF, SELECT, WHERE, [...]

  3. [...] (Name or IP of the server, the name of the database and table name in the SELECT statement) so that everything works fine. Dim cnn As New SqlConnection ("Data Source = MyServidor; Initial [...]

  4. eRzQrhGzy says:

  5. zASHPgEBwEbCFAB says:

  6. uMMpiwjrPaXAw says:

  7. lyperapse says:

    Improves test scores chewing gum small business utilization plan

Comment