Using SQL statements in ASP 12: Connecting

Source: Internet
Author: User
Tags contains join one table table name
Statement any person familiar with SQL and relational databases has encountered a large number of connection types. In the simplest sense, a join (join) combines the contents of two tables into a single virtual table or recordset. If the data table is effectively regulated, you may often select specific information from one table and then select the associated information from another table. This requires a simple "equivalent connection (equijoin)".

To understand the actual connection operation, let's now assume that there are records of some kind of software stored in a database. A table (Software) contains the name of the SOFTWARE product, the version of the software, and other relevant details: [Image004.gif]




The other table (releases) stores information about the history of the software release, including the release date and publication status (such as beta, current, obsolete, etc.): [Image005.gif]




The table also contains a column that points to the ID number taken in the Software table. So, by the way you index the software table, you know that the software that software_id equals 2 in the publishing table is Rome.

You use a combination of connections so that you don't have to toss back and forth between the two tables. However, in addition to the combination of information, you can merge related information through a connection. In this way, as soon as the software_id in the publication table matches the IDs in the software table, you put the matching information together in a record.

The code is as follows:
SQL = "SELECT * from Software, releases where software.id = Releases.softwareid"

With a careful analysis of the above statements, first notice that two tables are listed behind from. Depending on the connection you are using, you may also find that the syntax changes (or the type of connection varies) in the future, but the above syntax is the most basic and shows how the data is combined. The WHERE clause here is used to compare a specific ID value. In the software table, an ID column exists. Similarly, there is a software_id column in the Releases table. To clarify the value you want to compare in the WHERE clause, you prefix with the table name followed by a dot number (.).

The following is the result of the connection selection data: [Image006.gif]




Note: When creating a connection, you should carefully consider the column that selects the data. The above code uses the * wildcard character to keep the reader focused on other parts of the select line of code. However, as you can see from the above figure, you cannot select the Softwareid column because the column has no added value as part of the recordset. Its function is to use the WHERE clause.



Related Article

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.