Вы находитесь на странице: 1из 3

Reynaldo G. Dominguez Jr. CSCI30A 1. SELECT Function - Select is a statement queries data from a table in a database.

Example Syntax : SELECT column_name(s) FROM table_name Example : SELECT first_name from student 2. INNER JOIN Function - The inner join will select all rows from both tables as long as there is a match between the columns we are matching on. Example Syntax : SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name Example : SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons INNER JOIN Orders ON Persons.P_Id=Orders.P_Id ORDER BY Persons.LastName 3. OUTER JOIN Definition - The SQL OUTER JOIN clause is a variation of the SQL JOIN clause enables a SELECT statement to access more than one table. The JOIN clause controls how tables are linked. It is a qualifier of the SQL FROM clause. Function is used when there is a need to merge data from two tables and to include all rows from both tables without depending on a match. Another use is to generate a large result set for testing purposes. Example Syntax : SELECT <column_name1>, <column_name2> <aggregate_function> FROM <table_name> LEFT OUTER JOIN <table_name> ON <join_conditions> Example : SELECT region.region_nbr, region.region_name, branch.branch_nbr, branch.branch_name FROM dbo.region LEFT OUTER JOIN dbo.branch ON branch.region_nbr = region.region_nbr ORDER BY region.region_nbr 4. LEFT JOIN Defintion - The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2). Function - The result of a left outer join (or simply left join) for table A and B always contains all records of the "left" table (A), even if the join-condition does not find any matching record in the "right" table (B). Example Syntax : SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name=table_name2.column_name Example : SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons LEFT JOIN Orders ON Persons.P_Id=Orders.P_Id ORDER BY Persons.LastName\ 5. RIGHT JOIN

Definition - The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no matches in the left table (table_name1). Function - A right join is one of the JOIN operations that allow you to specify a JOIN clause. It preserves the unmatched rows from the second (right) table, joining them with a NULL in the shape of the first (left) table. Example Syntax : SELECT column_name(s) FROM table_name1 RIGHT JOIN table_name2 ON table_name1.column_name=table_name2.column_name Example : SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo FROM Persons RIGHT JOIN Orders ON Persons.P_Id=Orders.P_Id ORDER BY Persons.LastName 6. SUM Definition - The SQL SUM aggregate function allows selecting the total for a numeric column. Example Syntax : SELECT SUM(Column1) FROM Table1 Example : SELECT SUM(SaleAmount) FROM Sales 7. SUBQUERRY Defintion - A subquery is a query that is nested inside a SELECT, INSERT, UPDATE, or DELETE statement, or inside another subquery. A subquery can be used anywhere an expression is allowed. In this example a subquery is used as a column expression named MaxUnitPrice in a SELECT statement. Example : Syntax : SELECT "column_name1" FROM "table_name1" WHERE "column_name2" [Comparison Operator] (SELECT "column_name3" FROM "table_name2" WHERE [Condition]) Example : SELECT SUM(Sales) FROM Store_Information WHERE Store_name IN (SELECT store_name FROM Geography WHERE region_name = 'West') 8. CREATE DATABASE Function - The CREATE DATABASE statement is used to create a database. Example : Syntax : Create database database_name Example : Create database my_database 9. CREATE TABLE

Function - The CREATE TABLE statement is used to create a table in a database. Definition A table is divided into rows and columns. Each row may represent a piece of data and each column represents a component of each data Example Syntax : CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, .... ) Example : CREATE TABLE Persons ( P_Id int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) )

Вам также может понравиться