+ All Categories
Home > Documents > SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management...

SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management...

Date post: 15-May-2019
Category:
Upload: dodat
View: 219 times
Download: 0 times
Share this document with a friend
12
Transcript
Page 1: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection
Page 2: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection

SELECT [DISTINCT | ALL]

{* | colExpression [AS newName]] [,…]}

FROM TableName [alias][,…]

[WHERE condition]

[GROUP BY columnList] [HAVING condition]

[ORDER BY columnList];

UNION, INTERSECT and EXCEPT can be used to connect two queries as above when the queries are “union-compatible”

Page 3: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection

Two tables, or the result of two queries, are union-compatible if they have the same structure.

Same number of columns

Corresponding columns have the same data types

Page 4: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection
Page 5: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection

Write a query to list all cities in which part manufacturers and suppliers are located

Page 6: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection

Write a query to list all cities in which part suppliers are located:

SELECT cityFROM P

INTERSECT

SELECT cityFROM S

Page 7: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection

Write a query to list all cities in which part manufacturers are located, but no supplier is located.

Page 8: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection

Write a query to list all cities in which part manufacturers are located, but no supplier is located.

SELECT cityFROM P

EXCEPT

SELECT cityFROM S

Page 9: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection

Account has been set up

Windows authentication is used

Page 10: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection
Page 11: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection
Page 12: SELECT [DISTINCT | ALL] {* | colExpression [AS newName]] [,…]} · Microsoft SQL Server Management Studio Edit View Debug Tools Window Community Help O r cws roper-ties Current connection

Recommended