You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+95-20Lines changed: 95 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,21 +27,25 @@ SQL, Structured Query Language, is a programming language designed to manage dat
27
27
### 4.Query for Outputting Sorted Data Using ‘Order By’
28
28
> This query orders the results with respect to the attribute which is referenced to using “Order By” – so for example, if that attribute is an integer data type, then the result would either be sorted in ascending or descending order; likewise, if the data type is a String then the result would be ordered in alphabetical order.
29
29
30
-
`SELECT EMP_ID, LAST_NAME FROM EMPLOYEE
31
-
WHERE CITY = 'Seattle' ORDER BY EMP_ID;`
30
+
```
31
+
SELECT EMP_ID, LAST_NAME FROM EMPLOYEE
32
+
WHERE CITY = 'Seattle' ORDER BY EMP_ID;
33
+
```
32
34
33
35
> The ordering of the result can also be set manually, using “asc ” for ascending and “desc” for descending.
34
36
35
-
`SELECT EMP_ID, LAST_NAME FROM EMPLOYEE_TBL
36
-
WHERE CITY = 'INDIANAPOLIS' ORDER BY EMP_ID asc;`
37
+
```
38
+
SELECT EMP_ID, LAST_NAME FROM EMPLOYEE_TBL
39
+
WHERE CITY = 'INDIANAPOLIS' ORDER BY EMP_ID asc;
40
+
```
37
41
38
42
### 5.Query for Outputting Sorted Data Using ‘Group By’
39
43
> The ‘Group By’ property groups the resulting data according to the specified attribute.
40
44
41
-
`SELECT Name, Age FROM Patients WHERE Age > 40
42
-
GROUP BY Age ORDER BY Name;`
43
-
44
-
45
+
```
46
+
SELECT Name, Age FROM Patients WHERE Age > 40
47
+
GROUP BY Age ORDER BY Name;
48
+
```
45
49
46
50
47
51
@@ -68,49 +72,120 @@ Simple – an average of a given attribute.
68
72
### 9. ALTER TABLE
69
73
> ALTER TABLE lets you add columns to a table in a database.
70
74
71
-
`ALTER TABLE table_name
72
-
ADD column_name datatype;`
75
+
```
76
+
ALTER TABLE table_name
77
+
ADD column_name datatype;
78
+
```
73
79
74
80
### 10. AND
75
81
> AND is an operator that combines two conditions. Both conditions must be true for the row to be included in the result set.
76
82
77
-
`SELECT column_name(s)
83
+
```
84
+
SELECT column_name(s)
78
85
FROM table_name
79
86
WHERE column_1 = value_1
80
-
AND column_2 = value_2;`
87
+
AND column_2 = value_2;
88
+
```
81
89
82
90
### 11. AS
83
91
> AS is a keyword in SQL that allows you to rename a column or table using an alias.
84
92
85
-
`SELECT column_name AS 'Alias'
86
-
FROM table_name;`
93
+
```
94
+
SELECT column_name AS 'Alias'
95
+
FROM table_name;
96
+
```
87
97
88
98
### 12. BETWEEN
89
99
> The BETWEEN operator is used to filter the result set within a certain range. The values can be numbers, text or dates.
90
100
91
-
`SELECT column_name(s)
101
+
```
102
+
SELECT column_name(s)
92
103
FROM table_name
93
-
WHERE column_name BETWEEN value_1 AND value_2;`
104
+
WHERE column_name BETWEEN value_1 AND value_2;
105
+
```
94
106
95
107
### 13. CASE
96
108
> CASE statements are used to create different outputs (usually in the SELECT statement). It is SQL's way of handling if-then logic.
97
-
`SELECT column_name,
109
+
```
110
+
SELECT column_name,
98
111
CASE
99
112
WHEN condition THEN 'Result_1'
100
113
WHEN condition THEN 'Result_2'
101
114
ELSE 'Result_3'
102
115
END
103
116
FROM table_name;
104
-
`
117
+
```
118
+
119
+
### 14. CREATE TABLE
120
+
> CREATE TABLE creates a new table in the database. It allows you to specify the name of the table and the name of each column in the table
121
+
```
122
+
CREATE TABLE table_name (
123
+
column_1 datatype,
124
+
column_2 datatype,
125
+
column_3 datatype
126
+
);
127
+
```
128
+
129
+
### 15. DELETE
130
+
> DELETE statements are used to remove rows from a table.
131
+
```
132
+
DELETE FROM table_name
133
+
WHERE some_column = some_value;
134
+
```
135
+
136
+
### 16. HAVING
137
+
> HAVING was added to SQL because the WHERE keyword could not be used with aggregate functions.
138
+
```
139
+
SELECT column_name, COUNT(*)
140
+
FROM table_name
141
+
GROUP BY column_name
142
+
HAVING COUNT(*) > value;
143
+
```
144
+
145
+
### 17. INNER JOIN
146
+
> An inner join will combine rows from different tables if the join condition is true.
147
+
```
148
+
SELECT column_name(s)
149
+
FROM table_1
150
+
JOIN table_2
151
+
ON table_1.column_name = table_2.column_name;
152
+
```
153
+
154
+
### 18. INSERT
155
+
> INSERT statements are used to add a new row to a table.
156
+
```
157
+
INSERT INTO table_name (column_1, column_2, column_3)
158
+
VALUES (value_1, 'value_2', value_3);
159
+
```
160
+
161
+
### 19. IS NULL/ IS NOT NULL
162
+
> IS NULL and IS NOT NULL are operators used with the WHERE clause to test for empty values.
163
+
```
164
+
SELECT column_name(s)
165
+
FROM table_name
166
+
WHERE column_name IS NULL;
167
+
```
168
+
169
+
### 20. LIKE
170
+
> LIKE is a special operator used with the WHERE clause to search for a specific pattern in a column.
171
+
```
172
+
SELECT column_name(s)
173
+
FROM table_name
174
+
WHERE column_name LIKE pattern;
175
+
```
176
+
177
+
105
178
106
179
107
180
### 9. Query for Creating a View
108
181
> A view is a tailored table that is formed as a result of a query. It has tables and rows just like any other table. It’s usually a good idea to run queries as independent views because this allows them to be retrieved later to view the query results, rather than computing the same command every time for a particular set of results.
109
182
110
-
`CREATE VIEW Failing_Students AS
183
+
```
184
+
CREATE VIEW Failing_Students AS
111
185
SELECT S_NAME, Student_ID
112
186
FROM STUDENT
113
-
WHERE GPA > 40;`
187
+
WHERE GPA > 40;
188
+
```
114
189
115
190
### 10. Query for Listing all Views
116
191
> This query lists all the views available in the schema.
0 commit comments