Module03

1,404 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,404
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
28
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Faculty Notes: Select - CHOOSE the columns in a table that you want returned by your query Where - FILTER the rows in a table that you want returned by your query Order By - SORT data selected from the table in a specified order
  • Faculty Notes : Char_length function returns the number of character for variable-length data in a table column. However for fixed-length data, it returns the defined length of the column. Reverse(expression) returns reverse of the characters for example if expression is “abcd”, it returns “dcba” Substring(expression, start, length) Returns part of a string where start specifies the character position at which the substring begins. length specifies the number of characters in the substring.
  • Faculty Notes : Datepart notations are given below- Year abbreviated as yy expects values 1753–9999 Quarter abbreviated as qq expected values 1–4 Month abbreviated as mm expected values 1–12 Week abbreviated as wk expected values 1–54 Day abbreviated as dd expected values 1–31 Dayofyear abbreviated as dy expected values 1–366 Weekday abbreviated as dw expected values 1– 7 (Sunday–Saturday) hour abbreviated as hh expected values 0–23 Minute abbreviated as mi expected values 0–59 Second abbreviated as ss expected values 0–59 millisecond abbreviated as ms expected values 0–999
  • Faculty Notes : Examples : select datalength('aaa') select host_id() select suser_name()
  • Faculty Notes: The aggregate functions work with any type of column; however there are few exceptions: sum and avg functions work only with the numeric columns of int, smallint, tinyint, decimal, numeric, float, and money. Min and max functions will not work with bit data types Only the count(*) works with text and image data types. Example : Use pubs go select sum(ytd_sales) [Total Sales] from titles select count (*)[Total Records], avg (price*2)[Average Price] from titles --counts null values as well select count (price)[Total Not Null Records], avg (price*2) [Average Price] from titles --doesn't count null values Select max (ytd_sales)[Max Sales], min (ytd_sales) [Max Sales] from titles
  • Faculty Notes: WHERE Clause Specifies the condition for the rows returned by a query. Syntax WHERE < search_condition > Arguments <search_condition> Defines the condition to be met for the rows to be returned. There is no limit to the number of predicates in <search_condition>.
  • Faculty Notes: Read the above slide. Read both the select statements. Explain the output of each statement as follows: The first statement displays the last name and salary of employees whose salary is equal to 30000 The second statement displays the Employee Id and Last name for employees whose manager name is ‘RAYMOND’
  • Faculty Notes: Read the Select statements. Explain the output of each statement as follows: The first statement displays the last name of employees whose salary is greater than 30000 The second statement displays the Employee Id and Last Name of employees whose salary is less than equal to 30000 The third statement displays the Employee Id whose Status is not ‘ACTIVE’
  • Faculty Notes: Between condition takes into account the lower and the upper limit In the above example the select statement will display last name of employees whose salary is between 30000 and 50000 including 30000 and 50000 IN condition takes into account on the values supplied In the above example the select statement will display employee id of employees whose manager id is 100 or 200 or 300
  • Faculty Notes: % Matches any string of zero or more characters. This wildcard character can be used as either a prefix or a suffix. The above Select statement displays the last name of all employees ending with ‘ram’ from the employee table Example: ‘%ram’ will fetch all those values which end in ‘ram’ ram , program, monogram, gram _ (under score) Matches any single character, and can be used as either a prefix or suffix. The above Select statement displays the last name of all employees ending with ‘at’ from the employee table and whose length is three characters. Example: bat , rat, sat, hat You can search for wildcard characters (% , _) also. There are two methods for specifying a character that would ordinarily be a wildcard: Use the ESCAPE keyword to define an escape character. When the escape character is placed in front of the wildcard in the pattern, the wildcard is interpreted as a character. For example, to search for the string 5% anywhere in a string, use: WHERE ColumnA LIKE '%5/%%' ESCAPE '/' In this LIKE clause, the leading and ending percent signs (%) are interpreted as wildcards, and the percent sign preceded by a slash (/) is interpreted as the % character.
  • Faculty Notes: In the above examples: Select statement will display last name , job id of all employees whose salary is less than equal to 15000 AND job id is ‘SE’ Select statement will display last name , job id of all employees whose salary is less than equal to 15000 OR job id is ‘SE’
  • Faculty Notes: Select statement will display last name , job id of all employees whose salary is less than equal to 15000 and NOT job id is ‘SE’
  • Faculty Notes : Distinct returns non repeating values To returns the first n rows mentioned in the function Percent returns the n percent rows from the total rows. This n value can range only between 0-100
  • Faculty Notes: Step through and explain the slide.
  • Faculty Notes: Joins Join conditions can be specified in either the FROM or WHERE clauses; specifying them in the FROM clause is recommended. WHERE and HAVING clauses can also contain search conditions to further filter the rows selected by the join conditions.
  • Faculty Notes : A cross join that does not have a WHERE clause produces the Cartesian product of the tables involved in the join. The size of a Cartesian product result set is the number of rows in the first table multiplied by the number of rows in the second table. The following example shows a Transact-SQL cross join. See ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/c4f98374-e8a7-4f73-8d0e-309bd94ad1ae.htm for more information.
  • Faculty Notes : Joins can be categorized as: Inner joins (the typical join operation, which uses some comparison operator like = or <>). These include equi-joins and natural joins. Inner joins use a comparison operator to match rows from two tables based on the values in common columns from each table. For example, retrieving all rows where the student identification number is the same in both the students and courses tables. The above stored procedure contains a select statement with INNER JOINS In above example, you can use a self-join to find out which authors in Oakland, California, live in the same postal code area. Since this query involves a join of the authors table with itself, the authors table appears in two roles. To distinguish these roles, you can temporarily and arbitrarily give the authors table two different correlation names—such as au1 and au2—in the from clause. These correlation names qualify the column names in the rest of the query.
  • Faculty Notes : Outer joins : Outer joins can be a left, a right, or full outer join. Outer joins are specified with one of the following sets of keywords when they are specified in the FROM clause: LEFT JOIN or LEFT OUTER JOIN The result set of a left outer join includes all the rows from the left table specified in the LEFT OUTER clause, not just the ones in which the joined columns match. When a row in the left table has no matching rows in the right table, the associated result set row contains null values for all select list columns coming from the right table. RIGHT JOIN or RIGHT OUTER JOIN. A right outer join is the reverse of a left outer join. All rows from the right table are returned. Null values are returned for the left table any time a right table row has no matching row in the left table. FULL JOIN or FULL OUTER JOIN. A full outer join returns all rows in both the left and right tables. Any time a row has no match in the other table, the select list columns from the other table contain null values. When there is a match between the tables, the entire result set row contains data values from the base tables. Cross joins. Cross joins return all rows from the left table, each row from the left table is combined with all rows from the right table. Cross joins are also called Cartesian products.
  • Faculty Notes : RIGHT JOIN or RIGHT OUTER JOIN. A right outer join is the reverse of a left outer join. All rows from the right table are returned. Null values are returned for the left table any time a right table row has no matching row in the left table. FULL JOIN or FULL OUTER JOIN. A full outer join returns all rows in both the left and right tables. Any time a row has no match in the other table, the select list columns from the other table contain null values. When there is a match between the tables, the entire result set row contains data values from the base tables. Cross joins. Cross joins return all rows from the left table, each row from the left table is combined with all rows from the right table. Cross joins are also called Cartesian products.
  • Faculty Notes: Review the key points on the slide. The key points should be used to summarize the content covered throughout this presentation.
  • Module03

    1. 1. Querying and Reporting Module 3
    2. 2. <ul><li>Arithmetic operators used in SQL </li></ul><ul><li>Built in Functions </li></ul><ul><li>Retrieving data with the select statements </li></ul><ul><li>Grouping Results sets </li></ul><ul><li>Joins </li></ul><ul><li>Sub queries </li></ul>Learning Objectives
    3. 3. <ul><li>At the end of this section, you should be able to work with: </li></ul><ul><li>Arithmetic operators used in SQL </li></ul><ul><li>Built in Functions </li></ul><ul><ul><li>String Functions </li></ul></ul><ul><ul><li>Date Functions </li></ul></ul><ul><ul><li>System Functions </li></ul></ul><ul><ul><li>Aggregate Functions </li></ul></ul><ul><li>Retrieving data with the select statements </li></ul><ul><ul><li>Based on Conditions </li></ul></ul><ul><ul><li>Limit Results </li></ul></ul>Module 3 : Agenda
    4. 4. Module 3 : Agenda <ul><li>Grouping Results sets </li></ul><ul><ul><li>Group by </li></ul></ul><ul><ul><li>Compute and Compute By </li></ul></ul><ul><li>Joins </li></ul><ul><ul><li>Natural Join </li></ul></ul><ul><ul><li>Equi Join </li></ul></ul><ul><ul><li>Self Join </li></ul></ul><ul><ul><li>Outer Join </li></ul></ul><ul><li>Sub queries </li></ul><ul><ul><li>In </li></ul></ul><ul><ul><li>Exists </li></ul></ul><ul><ul><li>Correlated sub queries </li></ul></ul>
    5. 5. SELECT Statement <ul><li>Use the SELECT statement to retrieve data from one or more tables: </li></ul><ul><li>SELECT <column(s) > </li></ul><ul><li>FROM <table> </li></ul><ul><li>[ WHERE <condition>] </li></ul><ul><li>[ ORDER BY <column(s) [ASC|DESC]>] </li></ul>table is the name of the table column is the name of the column in the table to be selected condition identifies the rows to be selected and is composed of column names, expressions, constraints, sub-queries and comparison operators column is the name of the column(s) used for sorting (order by)
    6. 6. Querying and Reporting <ul><li>Selection : Querying for selection retrieves a subset of the rows in one or more tables. </li></ul><ul><ul><li>Example </li></ul></ul><ul><li>Projection : Querying for projection retrieves a subset of the columns in one or more tables. </li></ul><ul><li>It is best to put each column chosen in a separate line </li></ul><ul><ul><li>Example </li></ul></ul><ul><ul><li>SELECT * </li></ul></ul><ul><ul><li>FROM emp </li></ul></ul><ul><ul><li>SELECT empno, </li></ul></ul><ul><ul><li>ename, </li></ul></ul><ul><ul><li>deptno </li></ul></ul><ul><ul><li>FROM emp </li></ul></ul>
    7. 7. <ul><li>Rearranging order of columns: </li></ul><ul><ul><li>Example </li></ul></ul><ul><li>Using Column aliases </li></ul><ul><ul><li>Example </li></ul></ul>Querying and Reporting (Continued) <ul><ul><li>SELECT ename as [Employee Name], </li></ul></ul><ul><ul><li>empno, </li></ul></ul><ul><ul><li>deptno </li></ul></ul><ul><ul><li>FROM emp </li></ul></ul><ul><ul><li>SELECT empname, </li></ul></ul><ul><ul><li>eno, </li></ul></ul><ul><ul><li>deptno </li></ul></ul><ul><ul><li>FROM emp </li></ul></ul>
    8. 8. Arithmetic Operators Modulo % Division / Addition + Multiplication * Subtraction - Operation Operator
    9. 9. Built in Functions <ul><li>Built in Functions are a T-SQL extension to SQL </li></ul><ul><ul><li>String Functions </li></ul></ul><ul><ul><li>Date Functions </li></ul></ul><ul><ul><li>System Functions </li></ul></ul><ul><ul><li>Aggregate Functions </li></ul></ul>
    10. 10. Built In Functions : String Functions Returns part of a string. Start s pecifies the character position at which the substring begins. length specifies the number of characters in the substring. substring ( expression , start , length ) Returns the reverse of the character or binary expression reverse ( expression ) Returns an integer representing the number of characters in a character expression or text value. char_length ( char_expr ) Returns the ASCII code for the first character in the expression. ascii ( char_expr ) Descriptions Functions
    11. 11. Built In Functions : Date Functions Returns date produced by adding datepart to given date. dateadd ( datepart , number, date ) Returns the time between the first and second date. You can specify the datepart as months, years, hours, etc. datediff (datepart, date, date) Returns part of date as an integer. datepart ( datepart, date ) Returns Current system date and time. getdate () Descriptions Functions
    12. 12. Built In Functions : System Functions Returns the length of the column datalength ( expression ) Returns the computer name Host_name () Returns the process id of the process. host_id ( ) Descriptions Functions
    13. 13. Use of Aggregate Functions <ul><li>Aggregate functions are used to summarize the data retrieved in a query. </li></ul>Total of the (distinct) values in the expression Sum ([all | distinct] expression ) Lowest value in the expression Min ( expression ) Highest value in the expression Max ( expression ) Number of selected rows – including null values count(*) Number of (distinct) non-null values in the expression Count ([all | distinct] expression ) Average of the (distinct) values in the expression Avg ([all | distinct] expression ) Description Aggregate Function
    14. 14. Selecting Rows – Search Based <ul><li>The method of restriction is the basis of the WHERE clause in SQL </li></ul><ul><li>Character strings and dates in the WHERE clause must be enclosed in single quotation marks (‘) </li></ul>
    15. 15. Rows may be limited by: <ul><li>EQUALS CONDITION </li></ul><ul><ul><li>Display rows based on an exact match of values </li></ul></ul><ul><ul><li>SELECT LastName, </li></ul></ul><ul><ul><li> Salary </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE Salary = 30000 </li></ul></ul><ul><ul><li>SELECT EmployeeId, </li></ul></ul><ul><ul><li> LastName </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE ManagerName = ‘RAYMOND’ </li></ul></ul>
    16. 16. Rows may be limited by: (Continued) <ul><li>>, <, <=, >= or <> CONDITION </li></ul><ul><ul><li>SELECT LastName </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE Salary > 30000 </li></ul></ul><ul><ul><li>SELECT EmployeeId, </li></ul></ul><ul><ul><li> LastName </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE Salary <= 30000 </li></ul></ul><ul><ul><li>SELECT EmployeeId </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE Status <> ‘ACTIVE’ </li></ul></ul>
    17. 17. Rows may be limited by: (Continued) <ul><li>BETWEEN CONDITION </li></ul><ul><ul><li>Display rows based on a range of values </li></ul></ul><ul><ul><li>SELECT LastName </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE Salary BETWEEN 30000 AND 50000 </li></ul></ul><ul><li>IN CONDITION </li></ul><ul><ul><li>Display rows based on a list of values </li></ul></ul><ul><ul><li>SELECT EmployeeId </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE ManagerId IN (100, 200, 300) </li></ul></ul>
    18. 18. Rows may be limited by: (Continued) <ul><li>LIKE CONDITION </li></ul><ul><ul><li>Performs wildcard searches of valid search string values </li></ul></ul><ul><ul><li>Can contain either literal characters or numbers </li></ul></ul><ul><ul><ul><li>% denotes zero or many characters </li></ul></ul></ul><ul><ul><ul><li>_ denotes one character </li></ul></ul></ul><ul><ul><li>Use ESCAPE identifier to search for the actual % and _symbols </li></ul></ul><ul><ul><li>SELECT LastName </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE LastName LIKE ‘%ram’ </li></ul></ul><ul><ul><li>SELECT LastName </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE LastName LIKE ‘_at’ </li></ul></ul>
    19. 19. Rows may be limited by: (Continued) <ul><li>LOGICAL CONDITION </li></ul><ul><ul><li>AND, OR, NOT </li></ul></ul><ul><ul><li>SELECT LastName , </li></ul></ul><ul><ul><li>JobId </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE Salary <= 15000 </li></ul></ul><ul><ul><li>AND JobId = ‘SE’ </li></ul></ul><ul><ul><li>SELECT LastName , </li></ul></ul><ul><ul><li>JobId </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE Salary <= 15000 </li></ul></ul><ul><ul><li>OR JobId = ‘SE’ </li></ul></ul>
    20. 20. Rows may be limited by: (Continued) <ul><li>LOGICAL CONDITION </li></ul><ul><ul><li>AND, OR, NOT </li></ul></ul><ul><ul><li>SELECT LastName , </li></ul></ul><ul><ul><li>JobId </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>WHERE Salary <= 15000 </li></ul></ul><ul><ul><li>AND NOT JobId = ‘SE’ </li></ul></ul>
    21. 21. Rows may be limited by: (Continued) <ul><li>Distinct </li></ul><ul><li>Top </li></ul><ul><li>Percent </li></ul><ul><ul><li>SELECT distinct au_id , </li></ul></ul><ul><ul><li>FROM titleauthor </li></ul></ul><ul><ul><li>SELECT Top(4) * </li></ul></ul><ul><ul><li>FROM titleauthor </li></ul></ul><ul><ul><li>SELECT Top 20 percent * </li></ul></ul><ul><ul><li>FROM titleauthor </li></ul></ul>
    22. 22. Sorting Rows <ul><li>ORDER BY clause </li></ul><ul><ul><li>ASC specifies an ascending order </li></ul></ul><ul><ul><li>DESC specifies a descending order </li></ul></ul><ul><ul><li>SELECT LastName, </li></ul></ul><ul><ul><li> Salary , </li></ul></ul><ul><ul><li> JobId </li></ul></ul><ul><ul><li>FROM Employee </li></ul></ul><ul><ul><li>ORDER BY Salary DESC, JobId ASC </li></ul></ul><ul><li>Display the result in descending order by the attribute salary </li></ul><ul><li>If two records have the same attribute value, the salary sorting criteria is in ascending order according to the attribute values of JobId </li></ul>
    23. 23. <ul><li>Group By – A group by expression can contain column names not present in the select list. </li></ul>Grouping Result Sets <ul><ul><li>SELECT type, </li></ul></ul><ul><ul><li> avg(price), </li></ul></ul><ul><ul><li> sum(ytd_sales) </li></ul></ul><ul><ul><li>FROM title s </li></ul></ul><ul><ul><li>Group by pub_id, type </li></ul></ul>
    24. 24. <ul><li>Compute clause provides a detail and summary rows with one select statement. </li></ul><ul><li>You can calculate more than one row aggregate. </li></ul>Grouping Result Sets <ul><ul><li>SELECT type, </li></ul></ul><ul><ul><li> price, </li></ul></ul><ul><ul><li> advance </li></ul></ul><ul><ul><li>FROM title s </li></ul></ul><ul><ul><li>Order by type </li></ul></ul><ul><ul><li>Compute sum(price), sum(advance) </li></ul></ul><ul><ul><li>SELECT type, </li></ul></ul><ul><ul><li> price, </li></ul></ul><ul><ul><li> advance </li></ul></ul><ul><ul><li>FROM title s </li></ul></ul><ul><ul><li>Order by type </li></ul></ul><ul><ul><li>Compute sum(price), sum(advance) By type </li></ul></ul>
    25. 25. Joins <ul><li>Joins compare two or more tables or views by specifying compare column. </li></ul><ul><li>It checks values in these columns row wise and links the rows with the matching values. </li></ul><ul><li>Joins can be applied to the tables of the own database or other databases (with select permissions) </li></ul>
    26. 26. <ul><ul><li>start of select, update, insert, delete, or subquery </li></ul></ul><ul><ul><li>from { table_list | view_list } </li></ul></ul><ul><ul><li>where [not] </li></ul></ul><ul><ul><li>[ table_name . | view_name .] column_name join_operator </li></ul></ul><ul><ul><li>[ table_name . | view_name .] column_name </li></ul></ul><ul><ul><li>[{and | or} [not] </li></ul></ul><ul><ul><li>[ table_name .| view_name .] column_name join_operator </li></ul></ul><ul><ul><li>[ table_nam e.| view_name .] column_name ]... </li></ul></ul><ul><ul><li>End of select, update, insert, delete, or subquery </li></ul></ul>Joins - Syntax
    27. 27. Joins – Cross Join <ul><li>When a join is applied without the WHERE clause it produces the Cartesian product of the tables involved in that join. </li></ul><ul><ul><li>USE AdventureWorks </li></ul></ul><ul><ul><ul><li> GO </li></ul></ul></ul><ul><li>SELECT p.SalesPersonID, </li></ul><ul><li>t.Name AS Territory </li></ul><ul><li>FROM Sales.SalesPerson p </li></ul><ul><li>CROSS JOIN Sales.SalesTerritory t </li></ul><ul><li>ORDER BY p.SalesPersonID; </li></ul>
    28. 28. Joins – Equi Join and Natural Join <ul><li>Joins based on equality are called as Equi Joins </li></ul><ul><li>When an Equi-join returns all the columns of both the tables it is known as Natural Join </li></ul>SELECT au_fname, pub_name FROM Authors, Publishers Where Authors.city=Publishers.city <ul><ul><ul><li>SELECT * </li></ul></ul></ul><ul><li>FROM Authors, Publishers </li></ul><ul><li>Where Authors.city=Publishers.city </li></ul>
    29. 29. Joins – Self Join <ul><li>When a join compares values within the same column of one table are called as self joins. </li></ul><ul><ul><li>USE pubs; </li></ul></ul><ul><ul><ul><li> GO </li></ul></ul></ul><ul><li>select au1.au_fname, </li></ul><ul><li>au2.au_fname, </li></ul><ul><li>from authors au1, </li></ul><ul><li>authors au2 </li></ul><ul><li>where au1.city = &quot;Oakland&quot; and au2.city = &quot;Oakland&quot; </li></ul><ul><li>and au1.state = &quot;CA&quot; and au2.state = &quot;CA&quot; </li></ul><ul><li>and au1.postalcode = au2.postalcode </li></ul>
    30. 30. Joins – Outer Join <ul><li>Outer joins include all the rows regardless of whether there are matching rows. </li></ul><ul><li>Outer Joins are of 3 types </li></ul><ul><ul><li>Left Outer </li></ul></ul><ul><ul><li>Right Outer </li></ul></ul><ul><ul><li>Full Outer </li></ul></ul>SELECT * FROM titles LEFT JOIN titileauthor ON titiles.title_id = titleauthor.title_id
    31. 31. Joins – Outer Join SELECT * FROM titles RIGHT JOIN titileauthor ON titiles.title_id = titleauthor.title_id SELECT * FROM titles FULL OUTER JOIN titileauthor ON titiles.title_id = titleauthor.title_id
    32. 32. Sub Queries <ul><li>A subquery is nested select statement in another select/insert/update/delete statement as a condition. </li></ul><ul><li>A subquery can be used as an expression. </li></ul><ul><li>When subquery can be evaluated as if it were an independent query it is called a Non correlated subquery. </li></ul><ul><li>When a subquery can not be evaluated as an independent query, but can reference columns in a table listed in the from list of the outer query, it is called a correlated subquery. </li></ul><ul><li>There are two types of subqueries </li></ul><ul><ul><li>Expression subqueries </li></ul></ul><ul><ul><li>Quantified predicate subqueries </li></ul></ul>
    33. 33. Sub Queries (Continued) <ul><li>Expression subqueries: The value retuned is always single value which is further used for comparison. </li></ul>SELECT title, price FROM titles WHERE price = ( SELECT price FROM titles WHERE title = 'Straight Talk About Computers')
    34. 34. Sub Queries (Continued) <ul><li>Quantified predicate subqueries: The value returned can range from 0..n. This query operates on lists introduced with IN or with a comparison operator. Further it can be used as an existence test with the EXISTS introduced with exists. </li></ul><ul><ul><li>Subqueries with IN </li></ul></ul>SELECT pub_name FROM publishers WHERE pub_id IN (SELECT pub_id FROM titles WHERE type = ‘business’)
    35. 35. <ul><ul><li>Subqueries with Exists </li></ul></ul>Sub Queries (Continued) SELECT pub_name FROM publishers WHERE EXISTS (SELECT * FROM titles WHERE pub_id = publishers.pub_id AND type = ‘business’)
    36. 36. <ul><ul><li>Correlated Subqueries </li></ul></ul>Sub Queries (Continued) SELECT table1.type FROM titles table1 WHERE table1.type IN (SELECT table2.type FROM titles table2 WHERE table1. pub_id ! = table2. pub_id )
    37. 37. <ul><li>You may find useful content on T-SQL joins on the following url: </li></ul><ul><li>Web sites: </li></ul><ul><ul><li>http://www.sqlteam.com/article/writing-outer-joins-in-t-sql </li></ul></ul><ul><ul><li>http://www.sqlmag.com/Article/ArticleID/5342/sql_server_5342.html </li></ul></ul><ul><ul><li>http://pietschsoft.com/post/2005/12/T-SQL-Join-Tables-by-a-Field-that-contains-a-delimited-string.aspx </li></ul></ul><ul><ul><li>ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/c4f98374-e8a7-4f73-8d0e-309bd94ad1ae.htm </li></ul></ul>Resources
    38. 38. Key Points <ul><li>SQL is an industry standard language for updating to, and getting information from, a database. </li></ul><ul><li>The basic and most common SQL statements are: SELECT, INSERT, UPDATE, DELETE. </li></ul>
    39. 39. Questions & Comments

    ×