After the user logs in, there will be two more links under the forum menu, namely: the theme I published and the theme I participate in. The former's query is simpler. You only need to query the theme released by the login user. You can write it as a selected theme post. If the theme posts and reply stickers here are in a data table. Each record is distinguished by only one field. The theme post and reply stickers are made. I do this. We know, in general, when the reply is released, the title can be omitted. This reply to the theme of the corresponding post. How did this query do it?
Let's take a look at the code of the moving network first:
The following is the code fragment:
Select Top 200 * From TOPIC WHERE TOPICID In (Select Top 200 Rootid from & NowuseBBS & WHERE POSTUSERID = & Userid & Order by Announderid DESC SC
Why are there small brackets in this query? What does it mean? And listen to the decomposition.
The query we generally use is a single -layer query, but the above query is two layers. It requires the server to form a result before processing the final query work, and then continue to continue the following query work according to the current query investigation. In other words, first execute the query in the small bracket (we call it a child query), and then the server starts to perform external queries and returns the correct result. This query is called nested query. The above query, the first layer of query is to check all the posts (including reply) published by the user in this version, and then check the theme of these stickers.
In addition to the above function, what are the benefits of nested query? If the statistical function is required to use the statistical function in the search condition (which is often used in analysis statistics), you can use nested query. For example, the code of the book with a book with average sales of all sales is now required. If it is written as the following query method:
SELECT TITLE_ID, QTY // Title_id is the book number, QTY is sales
From Sales
Where QTY> AVG (QTY) // AVG is the average function, AVG (QTY) is the average sales volume
The server will prompt an error because the statistical function of the data of the SELECT list is not allowed in the where clause. By using nested queries in the where clause, this problem can be solved. The grammar is as follows:
The following is the code fragment:
Select title_id, QTY
From Sales
Where qty>
(SELECT AVG (QTY) from Sales)