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
+20-3Lines changed: 20 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,30 +7,39 @@ SQL, Structured Query Language, is a programming language designed to manage dat
7
7
8
8
### 1.Query for Retrieving Tables
9
9
> This query can be run to retrieve the list of tables present in a database where the database is “My_Schema”.
10
+
10
11
`SELECT * FROM My_Schema.Tables;`
11
12
12
13
### 2. Query for Selecting Columns from a Table
13
14
> This is perhaps the most widely used SQL query. In the example below, we are extracting the “Student_ID” column or attribute from the table “STUDENT”.
15
+
14
16
`SELECT Student_ID FROM STUDENT;`
15
17
16
18
> If you want to display all the attributes from a particular table, this is the right query to use:
19
+
17
20
`SELECT * FROM STUDENT;`
18
21
19
22
### 3.Query for Outputting Data Using a Constraint
20
23
> This query retrieves the specified attributes from the table on the constraint Employee ID =0000
24
+
21
25
`SELECT EMP_ID, NAME FROM EMPLOYEE_TBL WHERE EMP_ID = '0000';`
22
26
23
27
### 4.Query for Outputting Sorted Data Using ‘Order By’
24
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
+
25
30
`SELECT EMP_ID, LAST_NAME FROM EMPLOYEE
31
+
26
32
WHERE CITY = 'Seattle' ORDER BY EMP_ID;`
27
33
28
34
> The ordering of the result can also be set manually, using “asc ” for ascending and “desc” for descending.
35
+
29
36
`SELECT EMP_ID, LAST_NAME FROM EMPLOYEE_TBL
37
+
30
38
WHERE CITY = 'INDIANAPOLIS' ORDER BY EMP_ID asc;`
31
39
32
40
### 5.Query for Outputting Sorted Data Using ‘Group By’
33
41
> The ‘Group By’ property groups the resulting data according to the specified attribute.
42
+
34
43
`SELECT Name, Age FROM Patients WHERE Age > 40
35
44
GROUP BY Age ORDER BY Name;`
36
45
@@ -43,40 +52,48 @@ GROUP BY Age ORDER BY Name;`
43
52
44
53
### 6.Data Manipulation Using COUNT
45
54
> This query displays the total number of customers by counting each customer ID. In addition, it groups the results according to the country of each customer.
55
+
46
56
`SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country;`
47
57
48
58
### 7. Data Manipulation Using SUM
49
59
> SUM calculates the total of the attribute that is given to it as an argument.
60
+
50
61
`SELECT SUM(Salary)FROM Employee WHERE Emp_Age < 30;`
51
62
52
63
### 8. Data Manipulation Using AVG
53
64
Simple – an average of a given attribute.
65
+
54
66
`SELECT AVG(Price)FROM Products;`
55
67
56
68
### 9. ALTER TABLE
57
69
> ALTER TABLE lets you add columns to a table in a database.
70
+
58
71
`ALTER TABLE table_name
59
72
ADD column_name datatype;`
60
73
61
74
### 10. AND
62
75
> AND is an operator that combines two conditions. Both conditions must be true for the row to be included in the result set.
76
+
63
77
`SELECT column_name(s)
64
78
FROM table_name
65
79
WHERE column_1 = value_1
66
80
AND column_2 = value_2;`
67
81
68
82
### 11. AS
69
83
> AS is a keyword in SQL that allows you to rename a column or table using an alias.
84
+
70
85
`SELECT column_name AS 'Alias'
71
86
FROM table_name;`
72
87
73
88
### 12. AVG
74
89
> AVG() is an aggregate function that returns the average value for a numeric column.
90
+
75
91
`SELECT AVG(column_name)
76
92
FROM table_name;`
77
93
78
94
### 13. BETWEEN
79
95
> The BETWEEN operator is used to filter the result set within a certain range. The values can be numbers, text or dates.
96
+
80
97
`SELECT column_name(s)
81
98
FROM table_name
82
99
WHERE column_name BETWEEN value_1 AND value_2;`
@@ -104,7 +121,7 @@ WHERE GPA > 40;`
104
121
> This query updates the view named ‘Product List’ – and if this view doesn’t exist, then the Product List view gets created as specified in this query.
0 commit comments