Access to the database (3)

Source: Internet
Author: User
Tags date mdb database sql tutorial query access database
Access to | data | Database Access database (3)

Hello everybody, I am Wuhan Hua Division's Sunwen. The previous lesson tells you how to open a database and do some of the most basic things about the Db2.mdb database. Everyone must feel that the benefit is not shallow bar. Oh!

Because we mentioned some SQL statements in the last lesson, some friends may not be familiar with SQL database commands. In fact, I know very little about SQL. So in order to get you to learn some SQL statements, I went to the school library yesterday to move to a two kg of the SQL tutorial, studied a night, and finally some harvest. Let me now introduce the basic syntax of SQL statements.

A. Select query statement

This is a very common statement, so it must be carefully mastered. It contains the following common elements:

1.select_list: Select the list, which indicates the columns and attributes we want to query
2.into clause: Description construct a new table with query results
3.from clause: Indicates in which table the column to query is
4.where clause: Indicates a query condition that shows which rows of data in a table are returned to the result collection
5.order BY clause: Describes the order of rows in the query result collection


Perhaps the above explanation is not quite understood, let me use the following example to let you know more.
(Note: The following examples do not apply to this sample database)

Example one: The following statement queries the business American book published in the titles table in 1991 and its price

Select Title,price from titles where DATEPART (year,pubdate) =1991 and type= ' business '
Where title and price represent the columns we are looking for, while titles represent the table in which these columns are located, and is a logical operator that expresses the need to satisfy both datepart (year,pubdate) =1991 and type= ' business ' two conditions. As for DatePart (year,pubdate), it is a SQL function that separates a date character from the year section in a date-type character.

Example two: The following statement shows the data for all columns in the discounts table:

SELECT * FROM Discounts
Note: The wildcard character in SQL is *


Example three: Limit the number of rows returned:

Select top 2 * from discount
Return to the first two lines
Select top 2 percent * discount
Returns a row of 2%


Example four: Return book price higher than $ $ and its price:

Select Title,price from titles where price>$20
In addition to being greater than, less than, equal to, and other basic operators, SQL also provides operators such as between and, for example, changing price>$20 to price between $ and $, so that it represents prices between 20$ and $ $. Of course, SQL also includes many operators that you can check yourself.

Example five: Prices in descending order, titles in ascending order:

ORDER BY Price Desc,title ASC
Where Desc represents a descending order, ASC represents a long order, and if this argument is not added, the system defaults to ascending order.

After introducing the above, I would like to remind you that the method of the string representation in SQL is expressed in single quotes ("") instead of double quotes (""), which is different when we write the program in ASP. Because of this, will have a lot of problems, some problems I can not solve, I also need to master guidance. Just introduce this point, if you later encounter SQL statements, and then introduce it.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.