-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-basics.sql
60 lines (50 loc) · 909 Bytes
/
query-basics.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
USE Northwind
GO
-- Select all columns
SELECT * FROM Products;
--Select a subset of columns
SELECT
ProductID
, ProductName
, UnitPrice
FROM
Products;
--Select a literal value
SELECT 'Hello world!';
SELECT 120.50;
-- An arithmetic expression
SELECT 12 * 4;
-- Get the product name of product id 1
SELECT
ProductName
FROM
Products
WHERE
ProductID = 1;
-- Get the product name and price of product ids 1, 2, 3, 4 and 5
SELECT
ProductID
, ProductName
, UnitPrice
FROM
Products
WHERE
ProductID IN (1,2,3,4,5);
-- Get the product name and unit price of products which names start with the letter C
SELECT
ProductName
, UnitPrice
FROM
Products
WHERE
ProductName LIKE 'C%';
-- Which of my products is the most expensive using ORDER BY
SELECT
ProductName
, UnitPrice
FROM
Products
WHERE
ProductID IN (15, 28, 38, 55, 77, 12, 47, 22, 39, 10)
ORDER BY
UnitPrice DESC;