Database query Language (1)

Source: Internet
Author: User
Data | Database originally planned to introduce the ActiveX components built into ASP in the beginning of this article, however, considering that we will be exposed to a large number of database queries in the future, the author temporarily decided to spend one or two pages to brief you on some basic knowledge of database query language, This is actually learning the ASP must master a knowledge. The flexibility of the use of database query language, will directly affect the implementation of ASP procedures, such as the efficiency of a series of issues, so please be sure to attach importance to.

I believe many friends have heard of the name of SQL, if you are a computer expert, the name of SQL must be thunderclap piercing. So what exactly is SQL? The word SQL is actually an abbreviation for the "Structured query Language" Structured Query Language, a tool for organizing, managing, and retrieving data stored in a computer database--a relational database of a particular type of database. and the computer program that controls this kind of database is we often say dbms--database management system. For example: SQL Server, Oracle, Sybase, DB2, and so on. When a user wants to retrieve data from a database, the request is made in the SQL language, and the DBMS processes the SQL request and retrieves the requested data and returns it to the user, which is called a database query, which is the origin of the name of the database query language.

SQL is not a complete computer language like C, COBOL, and Fortran languages. SQL does not have an IF statement for a conditional test, a Goto statement for a program branch, and a loop statement for or do. Specifically, SQL is a database child language, and SQL statements can be embedded in another language, enabling them to have database access capabilities. SQL is also not a strict structured language, its syntax is closer to English sentences, so easy to understand, most of the SQL statements are straight to the meaning, read as the natural language as clear. SQL is also an interactive query language that allows users to directly query for stored data, and with this interaction, users can answer fairly complex questions in a short period of time, and the same problem can take weeks or longer if the programmer writes the appropriate reporting program.

In most ASP applications we have access to the database, and the standard syntax for database operations when we write an ASP application is SQL, so the importance of SQL syntax is self-evident. Next, we start with the most commonly used SQL statement SELECT to learn SQL Step-by-step.

Queries are the core of the SQL language, and the SELECT statement for expressing SQL queries is the most powerful and complex SQL statement that retrieves data from the database and provides the results to the user. In this article, we'll build a simple database called Tianjiao, which holds a sales record table named Sale, as follows:

Name sex wage sales target sales area scholar male 250080009000 Shanghai Wu Guanjun male 3000100009999 Beijing Thunder male 20,008,000,100,004 Sichuan snow son 250050006000 Guangzhou Gu Yinan 260090009800 Dalian Zhuo female 200040004000 Tianjin Yi Day Man 40002000020000 National

There are six columns or six fields in the table: name, sex, salary, sales target, sales, region, first we use the Select statement to List names, sales targets, and sales:

Select name, sales target, sales from sales

The results are as follows:

Name Sales target sales scholar 80009000 Wu Guanjun 100009999 Thunder 800010000 snow son 50006000 gu 190.0098 million Zhuo 40004000 Yi days 2000020000

Then, we list all men's names, sales targets, and sales:

Select name, sales target, sales from sales Where sex = "male"

The results are as follows:

Name Sales target sales scholar 80009000 Wu Guanjun 100009999 Thunder 800010000 gu 190.0098 million yi days 2000020000

Next, we make a relatively complex query that lists the names, sales targets, and sales of all men whose sales are larger than the sales target, sorted by sales target.
Select name, sales target, sales
Form Sales
Where Sales > Sales targets
and gender = "male"
Order BY sales target

The results are as follows:

Name Sales target sales scholar 80009000 Thunder 800010000 gu 190.0098 million yi days 2000020000

[1] [2] Next page



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.