Vous êtes sur la page 1sur 3

GROUP BY Clause WHERE clause).

Subqueries as output (those in the SELECT list)


Syntax are not allowed in crosstab queries.
SELECT fieldlist
FROM table LEFT JOIN, RIGHT JOIN Operations
WHERE criteria Combines source-table records when used in any FROM
[GROUP BY groupfieldlist] clause.

Syntax
HAVING Clause FROM table1 [ LEFT | RIGHT ] JOIN table2
Syntax ON table1.field1 compopr table2.field2
SELECT fieldlist The LEFT JOIN and RIGHT JOIN operations have these parts:
FROM table
WHERE selectcriteria Part Description
GROUP BY groupfieldlist
[HAVING groupcriteria] table1, The names of the tables from which records are
table2 combined.
SELECT CategoryID,
Sum(UnitsInStock) field1, The names of the fields that are joined. The fields
FROM Products field2 must be of the same data type (data type: The
GROUP BY CategoryID characteristic of a field that determines what type
HAVING Sum(UnitsInStock) > 100 And Like "BOS*"; of data it can hold. Data types include Boolean,
Integer, Long, Currency, Single, Double, Date,
ORDER BY Clause String, and Variant (default).) and contain the same
Syntax kind of data, but they do not need to have the same
SELECT fieldlist name.
FROM table compopr Any relational comparison operator: "=," "<," ">,"
WHERE selectcriteria "<=," ">=," or "<>."
[ORDER BY field1 [ASC | DESC ][, field2 [ASC | DESC ]][, ...]]]
The following example shows how you could join the Categories
SELECT LastName, FirstName and Products tables on the CategoryID field. The query produces
FROM Employees a list of all categories, including those that contain no products:
ORDER BY LastName ASC;
SELECT CategoryName, ProductName FROM Categories LEFT
SELECT LastName, Salary JOIN Products ON Categories.CategoryID =
FROM Employees Products.CategoryID;
ORDER BY Salary DESC, LastName;
To create a query that includes only records in which the data in
WITH OWNERACCESS OPTION Declaration the joined fields is the same, use an INNER JOIN operation.
Syntax A LEFT JOIN or a RIGHT JOIN can be nested inside an
sqlstatement INNER JOIN, but an INNER JOIN cannot be nested inside
WITH OWNERACCESS OPTION a LEFT JOIN or a RIGHT JOIN. See the discussion of
nesting in the INNER JOIN topic to see how to nest joins
SELECT LastName, FirstName, Salary within other joins.
FROM Employees You can link multiple ON clauses. See the discussion of
ORDER BY LastName clause linking in the INNER JOIN topic to see how this is
WITH OWNERACCESS OPTION; done.
SQL Subqueries INNER JOIN Operation
A subquery is a SELECT statement nested inside a Combines records from two tables whenever there are
SELECT, SELECT...INTO, INSERT...INTO, DELETE, or matching values in a common field.
UPDATE statement or inside another subquery.
Syntax
Syntax FROM table1 INNER JOIN table2 ON table1.field1 compopr
You can use three forms of syntax to create a subquery: table2.field2
comparison [ANY | ALL | SOME] (sqlstatement)
expression [NOT] IN (sqlstatement) The following example shows how you could join the Categories
[NOT] EXISTS (sqlstatement) and Products tables on the CategoryID field:
A subquery has these parts:
Part Description SELECT CategoryName, ProductName
FROM Categories INNER JOIN Products
compariso An expression (expression: Any combination of ON Categories.CategoryID = Products.CategoryID;
n mathematical or logical operators, constants,
functions, and names of fields, controls, and You can also link several ON clauses in a JOIN
properties that evaluates to a single value. statement, using the following syntax:
Expressions can perform calculations, manipulate SELECT fields
characters, or test data.) and a comparison FROM table1 INNER JOIN table2
operator that compares the expression with the ON table1.field1 compopr table2.field1 AND
results of the subquery. ON table1.field2 compopr table2.field2) OR
ON table1.field3 compopr table2.field3)];
expression An expression for which the result set of the You can also nest JOIN statements using the following syntax:
subquery is searched.
sqlstateme A SELECT statement, following the same format SELECT fields
FROM table1 INNER JOIN
nt and rules as any other SELECT statement. It must
(table2 INNER JOIN [( ]table3
be enclosed in parentheses.
[INNER JOIN [( ]tablex [INNER JOIN ...)]
ON table3.field3 compopr tablex.fieldx)]
SELECT * FROM Products WHERE UnitPrice > ANY (SELECT ON table2.field2 compopr table3.field3)
UnitPrice FROM OrderDetails WHERE Discount >= .25); ON table1.field1 compopr table2.field2;

SELECT LastName, FirstName, Title, Salary FROM A LEFT JOIN or a RIGHT JOIN may be nested inside an INNER
Employees AS T1 WHERE Salary >= (SELECT Avg(Salary) JOIN, but an INNER JOIN may not be nested inside a LEFT JOIN or
FROM Employees WHERE T1.Title = Employees.Title) Order a RIGHT JOIN.
by Title;
UNION Operation
In the preceding example, the AS reserved word (reserved word: Creates a union query (union query: A query that uses
A word that is part of a language, such as Visual Basic. Reserved the UNION operator to combine the results of two or
words include the names of statements, predefined functions more select queries.), which combines the results of two
and data types, methods, operators, and objects.) is optional. or more independent queries or tables.
Some subqueries are allowed in crosstab queries (crosstab
query: A query that calculates a sum, average, count, or other Syntax
type of total on records, and then groups the result by two types [TABLE] query1 UNION [ALL] [TABLE] query2 [UNION [ALL]
of information: one down the left side of the datasheet and the [TABLE] queryn [ ... ]]
other across the top.) — specifically, as predicates (those in the
You can merge the results of two or more queries, tables, and EXEC, EXECUTE FROM Clause
SELECT statements, in any combination, in a single UNION
EXISTS GENERAL — See LONGBINARY
operation. The following example merges an existing table
named New Accounts and a EXTRACT GRANT

FALSE GROUP
SELECT statement:
TABLE [New Accounts] UNION ALL FETCH GUID
SELECT *
FIRST HAVING
FROM Customers
WHERE OrderAmount > 1000; FLOAT, FLOAT8 — See HOUR
DOUBLE
SQL Reserved Words FLOAT4 — See SINGLE
Note Words followed by an asterisk (*) are reserved but
currently have no meaning in the context of a Microsoft Access IDENTITY INPUT
SQL statement IEEEDOUBLE — See DOUBLE INSENSITIVE

IEEESINGLE — See SINGLE INSERT

IGNORE INSERT INTO

IMAGE INT, INTEGER, INTEGER4 — See


LONG

Imp INTEGER1 — See BYTE

In INTEGER2 — See SHORT


ANY
ABSOLUTE IN INTERVAL

ADD ARE INDEX INTO

ADMINDB AS INDEXCREATEDB Is

ALL ASC INNER ISOLATION

Alphanumeric — See TEXT ASSERTION JOIN LONGTEXT

ALTER AUTHORIZATION KEY LOWER

ALTER TABLE AUTOINCREMENT — See COUNTER LANGUAGE MATCH

And Avg LAST Max

AS LEFT MEMO — See LONGTEXT

BEGIN COLLATION Level* Min

Between COLUMN Like MINUTE

BINARY COMMIT LOGICAL, LOGICAL1 — See BIT Mod

BIT COMP, COMPRESSION LONG MONEY — See CURRENCY

BIT_LENGTH CONNECT LONGBINARY MONTH

BOOLEAN — See BIT CONNECTION LONGCHAR

BOTH CONSTRAINT, CONSTRAINTS NATIONAL Outer*

BY CONTAINER NCHAR OUTPUT

BYTE CONTAINS NONCLUSTERED OWNERACCESS

CASCADE CONVERT Not PAD

CATALOG Count NTEXT PARAMETERS

CHAR, CHARACTER — See COUNTER NULL PARTIAL


TEXT
NUMBER — See DOUBLE PASSWORD
CHAR_LENGTH CREATE
NUMERIC — See DECIMAL PERCENT
CHARACTER_LENGTH CURRENCY
NVARCHAR PIVOT
CHECK CURRENT_DATE
OCTET_LENGTH POSITION
CLOSE CURRENT_TIME
OLEOBJECT — See LONGBINARY PRECISION
CLUSTERED CURRENT_TIMESTAMP
ON PREPARE
COALESCE CURRENT_USER
OPEN PRIMARY
COLLATE CURSOR
OPTION PRIVILEGES
DATABASE DISALLOW
Or PROC, PROCEDURE

ORDER PUBLIC
DATE — See DATETIME DISCONNECT
REAL — See SINGLE SMALLDATETIME

DATETIME DISTINCT
REFERENCES SMALLINT — See SHORT

DAY DISTINCTROW
RESTRICT SMALLMONEY

DEC, DECIMAL DOMAIN


REVOKE SOME

DECLARE DOUBLE
RIGHT SPACE

DELETE DROP
ROLLBACK SQL

DESC
SCHEMA SQLCODE, SQLERROR, SQLSTATE

Eqv FOREIGN

EXCLUSIVECONNECT FROM
SECOND StDev UPDATE ZONE

SELECT StDevP UPDATEIDENTITY

SELECTSCHEMA STRING — See TEXT

SELECTSECURITY SUBSTRING

SET Sum

SHORT SYSNAME

SINGLE SYSTEM_USER

SIZE

TABLE UPDATEOWNER

TableID* UPDATESECURITY

TEMPORARY UPPER

TEXT USAGE

TIME — See DATETIME USER

TIMESTAMP USING

TIMEZONE_HOUR VALUE

TIMEZONE_MINUTE VALUES

TINYINT Var

TO VARBINARY — See
BINARY

TOP VARCHAR — See TEXT

TRAILING VarP

TRANSACTION VARYING

TRANSFORM VIEW

TRANSLATE WHEN

TRANSLATION WHENEVER

TRIM WHERE

TRUE WITH

UNION WORK

UNIQUE Xor

UNIQUEIDENTIFIER YEAR

UNKNOWN YESNO — See BIT

Vous aimerez peut-être aussi