forked from syedmurad1/SQLbasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQL-2.txt
102 lines (53 loc) · 1.77 KB
/
SQL-2.txt
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
IN
Tests to see if an item value appears in a specified list of values.
NOT IN
Tests to see if an item value does NOT appear in a specified list of values.
SELECT *
FROM Stationery
WHERE item_code in (20217, 33008, 33015);
............................................................................
LIKE
Tests to see if an item value matches a string containing wildcard characters.
The wildcard characters % meaning zero or more occurrences of any character
NOT LIKE
Tests to see if an item value does NOT match a string containing wildcard characters.
The wildcard characters % meaning zero or more occurrences of any character
SELECT *
FROM Stationery
WHERE colour like ‘R%’;
List all data from Stationery relation that contains the word ‘Ring’ in the item name.
SELECT *
FROM Stationery
WHERE item_name like ‘%Ring%’;
................................................................................
IS NULL
Tests to see if an item has a Null value.
IS NOT NULL
Tests to see if an item does NOT have a Null value.
SELECT item_code, price, colour, quantity
FROM stationery
WHERE item_name is null;
................................................................................
The logical operators:
AND / OR
SELECT item_code, item_name
FROM Stationery
WHERE colour = ‘Red’
OR colour =‘Blue’;
......................................................................................
BETWEEN
SELECT *
FROM Stationery
WHERE price BETWEEN 1.50 and 2.75;
..................................................................................
ORDER BY
SELECT *
FROM Stationery
ORDER BY quantity ASC;
SELECT *
FROM Stationery
ORDER BY price DESC;
SELECT *
FROM Stationery
ORDER BY quantity ASC, price DESC;