Discover sql nested query example, include the articles, news, trends, analysis and practical advice about sql nested query example on alibabacloud.com
SQL Optimization-logical Optimization-external connections, nested connections, and elimination of connections, SQL nesting
1) eliminate external connections
① External connection Introduction
1) left join/left outer join: LEFT OUTER JOIN
The result set of left outer Join includes all rows in the LEFT table specified in the left outer clause, not jus
(a) Nested query 1. Ask for the ' MA ' number and name. Sql> Select Sno,sname from student where Sno in (select Sno from SC where cno= (select CNO from course where cname= ' math ')) ; 2. Check with Liu Ming in the same department to study students. Sql> SELECT * FROM student where sdept= (select Sdept from student whe
when the system is not running. In the online use area, select the verification method used for online SQL Server. If you choose to use Windows Account Verification, you do not need to specify the user name or password, because Windows 2000 account will be used to verify access to SQL Server. If you choose to use SQL Server account authentication, you must speci
' √ '
Else
"'
End) allow null, IsNull (E.text,"') default value, IsNull (g.value,"') asDescription fromSyscolumns A Left JoinSystypes b onA.xtype = B.xusertypeInner Joinsysobjects D ona.ID = D.id andD.xtype =' U '
andD.name ' dtproperties '
Left Joinsyscomments E onA.cdefault = e.id Left JoinSys.extended_properties g ona.ID = g.major_id andA.colid = g.minor_id Left JoinSys.extended_properties F onD.id = F.class andf.minor_id =0
whereB.name is not NUL
SQL Federated Query and XML parsing instance
Here is an example of how to implement this feature:
(select A.ebillno, A.empname, A.applydate, B.hs_name, replace (A.summary,char (), '), char (), ') as SUMMARY, Cast (C.xmldata as XML). Value (' (/list/item/no/text ()) [1] ', ' NVARCHAR ') as No, cast (C.xmldata as XML). Value (' (/list /item/zje/text ()) [1]
up to 32 layers. Individual queries may not support 32-tier nesting. 5. Any place where you can use an expression can use a subquery, as long as it returns a single value. 6. If a table appears only in the subquery and does not appear in the outer query, the columns of the table cannot be included in the output. three, simple sub-query Example: Select from pers
SQL Example 9– subqueryDatabase PreparationCreate Table Student(IDintAuto_incrementPrimary Key,name varchar(10));Create Table scores(IDintAuto_incrementPRIMARY Key, scoreint default0,Foreign Key(ID)ReferencesStudent (ID) on Delete Cascade on Update Cascade);A subquery can return a scalar, a row, a column, or a subquerySELECT * from t1 where column1 = (select Column1 from T2);The first select is called an o
sum_column1FROM t1 GROUP BY column1) AS t1;
2. Row Subquery)
See the following example:Copy codeThe Code is as follows: SELECT * FROM t1 where row (1, 2) = (SELECT column1, column2 FROM t2 );
This query returns the result line with column1 equal to column2. The values 1 and 2 in the Row function are equivalent to the constructor parameters. Presumably, the comrades on Blogjava should be clear about this and will not go into details.
3. Use the Exist
program ape. For example, a character intercept occurs when a program passes a character field value in a table to a sequence principal variable that is shorter than its length. Although Sqlcode returns +0 at this point, the data obtained by the program is incomplete. By specifying an indicator variable for the ordinal primary variable. When the same error occurs, the return value of Sqlwarn[o] and Sqlwarn[1] is W. At the same time, the indicator var
(select sum (column1) as sum_column1 to
T1 GROUP by column1) as T1;
2. Subquery for row (row subquery)
Look at the following example:
Copy Code code as follows:
SELECT * from T1 WHERE ROW (1,2) = (select Column1, column2 from T2);
This query is the result row that returns Column1 equals Column2. 1 and 2 in the row function are equivalent to the construction parameters. Presumably
to 32 layers. Individual queries may not support 32-tier nesting. 5. Any place where you can use an expression can use a subquery, as long as it returns a single value. 6. If a table appears only in the subquery and does not appear in the outer query, the columns of the table cannot be included in the output.Three, simple sub-queryExample: Select Name,age from
-person where >
(select-age-from-person
WHERE name = ' Sun Quan '
) The output is:
1. Meaning of withThe with as phrase, also known as subquery factoring, allows you to do a lot of things and define an SQL segment, which will be used by the entire SQL statement. Sometimes, it is to make the SQL statement more readable, or it may be in different parts of Union all, as part of the provided data.Especially useful for Union all. Because each part o
Sqlcode after each SQL statement is executed to monitor the operation of the program. When the return value is +0, the SQL statement executes successfully, and a return value of +100 indicates that the record that satisfies the search criteria was not found. In general, negative sqlcode returns negative meaning that SQL statement execution fails, and programmers
Tags: scenario date Another content like common is the CTO solvesA Meaning of with ASThe with as phrase, also called the subquery section (subquery factoring), allows you to do many things, defining a SQL fragment that will be used by the entire SQL statement. Sometimes it is to make the SQL statement more readable, or it may be in different parts of union all as
(' Commentview '); Instantiate the comment view model $articleComments = $article-> where (Array (' aid ' => $aid, ' pid ' => 0)-> limit Select (); Query first-level comments Www.111cn.net foreach ($articleComments as $comment) { $comments [$comment [' id ']] = $comment; /Assign query-level comments to comments array } by id $commentID = Array_keys ($comments);//Remove the ID of the first level of comm
is the meaning? And listen to the next decomposition.
The queries we use generally are single level queries, the above query is a two-tier, which requires the server to process the final query before the results of a result, and then according to the current query knot to further continue the following query work,
Tags: style blog http io color ar using for SPExt.: http://wudataoge.blog.163.com/blog/static/80073886200961652022389/A Meaning of with ASThe with as phrase, also called the subquery section (subquery factoring), allows you to do many things, defining a SQL fragment that will be used by the entire SQL statement. Sometimes it is to make the SQL statement more read
. Therefore, you can use the with as phrase, Hong Kong server, you only need to execute it once. If the table name defined by the with as phrase is called more than twice, the optimizer automatically puts the data obtained by the with as phrase into a TEMP table. If it is called only once, no. The prompt materialize is to forcibly put the data in the with as phrase into a global temporary table. This method improves the speed of many queries.Ii. UsageFirst, let's look at the following
Today in the project encountered about MongoDB nested query, has not been contacted before, query the relevant data to record the results.
The data in the MongoDB are as follows:
> Db.customer.findOne ()
{
"_id": ObjectId ("57636c8e35defe029962107e"),
"_class": " Com.bu2trip.ticket.model.Customer ",
" name ":" Wang ",
" phone ":" 18408221624 ",
In the current information society, information is the lifeline, and a large amount of information is stored in the database.
Dataset provides a good data method for data access, but because it is a data set in the memory, if the data in the data table is large, for example, hundreds of thousands, it occupies more than a dozen gigabytes of space, so the server's memory will be far from enough to meet the needs. If there are thousands of people simulta
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.