├── LICENSE ├── README.md └── employee.sql /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Valentine Fernandes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

MYSQL ASSIGNMENT

2 | 3 | # CREATE DATABASE 4 | 5 | ```javascript 6 | CREATE DATABASE testdb; 7 | ``` 8 | 9 | # SHOW EXISTING DATABASE 10 | 11 | ```javascript 12 | SHOW CREATE DATABASE testdb; 13 | ``` 14 | # USE COMMAND 15 | 16 | ```javascript 17 | USE testdb; 18 | ``` 19 | 20 | # CREATE TABLE EMPLOYEE 21 | 22 | ```javascript 23 | CREATE TABLE Employee 24 | ( 25 | EmployeeID int, 26 | FirstName varchar(255), 27 | LastName varchar(255), 28 | Email varchar(255), 29 | AddressLine varchar(255), 30 | City varchar(255) 31 | ); 32 | ``` 33 | 34 | # INSERT RECORDS IN EMPLOYEE TABLE 35 | 36 | ```javascript 37 | INSERT INTO Employee (EmployeeID, FirstName, LastName, Email, AddressLine, City) 38 | VALUES ('101', 'Lucas', 'Santos', 'lucassantos@gmail.com', 'Brazil', 'Sao Paulo'), 39 | ('102', 'Carlos', 'Santiago', 'carlossantiago@gmail.com', 'Argentina', 'Buenos Aires'), 40 | ('103', 'Emanuel', 'DaSilva', 'emanueldasilva@gmail.com', 'Brazil', 'Rio Grande do Sul'), 41 | ('104', 'Abril', 'Rodriguez', 'abrilrodrigues@gmail.com', 'Argentina', 'Mendoza'), 42 | ('105', 'Carolina', 'Bentresca', 'carolinabentresca@gmail.com', 'Chile', 'Concepsion'), 43 | ('106', 'Carol', 'Santos', 'carolsantos@gmail.com', 'Chile', 'Santiago'), 44 | ('107', 'Gabriela', 'Lopez', 'Gabrielalopez@gmail.com', 'Brazil', 'Amazonas'), 45 | ('108', 'Michael', 'DeCarvalho', 'michaeldecarvalho@gmail.com', 'Brazil', 'Fortaleza'), 46 | ('109', 'George', 'Spencer', 'georgespencer@gmail.com', 'United Kingdom', 'London'), 47 | ('110', 'Christina', 'Diemert', 'christinadiemert@gmail.com', 'United States', 'California'); 48 | ``` 49 | 50 | # QUERIES 51 | 52 | 1. From the following table return complete information about the employees. 53 | 54 | ```javascript 55 | SELECT * FROM Employee; 56 | ``` 57 | 58 | 2. From the following table, write a SQL query to find the cities of all employees. Return city. 59 | 60 | ```javascript 61 | SELECT City FROM Employee; 62 | ``` 63 | 64 | 3. From the following table, write a SQL query to find the unique addressline of the employees. Return addressline. 65 | 66 | ```javascript 67 | SELECT DISTINCT AddressLine 68 | FROM Employee; 69 | ``` 70 | 71 | 4. From the following table, write a SQL query to return EmployeeID, FirstName, LastName, City and AddressLine. 72 | 73 | ```javascript 74 | SELECT EmployeeID, 75 | FirstName, 76 | LastName, 77 | City, 78 | AddressLine 79 | FROM Employee; 80 | ``` 81 | 82 | 5. From the following table, write a SQL query to count the number of characters except the spaces for each FirstName. Return FirstName length. 83 | 84 | ```javascript 85 | SELECT length(trim(FirstName)) 86 | FROM Employee; 87 | ``` 88 | 89 | 6. From the following table, write a SQL query to count the number of characters except the spaces for each LastName. Return LastName length. 90 | 91 | ```javascript 92 | SELECT length(trim(LastName)) 93 | FROM Employee; 94 | ``` 95 | 96 | 7. From the following table, write a SQL query to find the EmployeeID, FirstName, Email of all the employees. 97 | 98 | ```javascript 99 | SELECT EmployeeID, 100 | FirstName, 101 | Email 102 | FROM Employee; 103 | ``` 104 | 105 | 8. From the following table, write a SQL query to find the unique AddressLine with LastName. Return AddressLine and LastName. 106 | 107 | ```javascript 108 | SELECT DISTINCT AddressLine, LastName 109 | FROM Employee; 110 | ``` 111 | 112 | 9. From the following table, write a SQL query to find those employees who do not belong to AddressLine Brazil. Return complete information about the employees. 113 | 114 | ```javascript 115 | SELECT * 116 | FROM Employee 117 | WHERE AddressLine NOT IN ('Brazil'); 118 | ``` 119 | 120 | 10. From the following table, write a SQL query to find those employees who do not belong to AddressLine Argentina. Return complete information about the employees. 121 | 122 | ```javascript 123 | SELECT * 124 | FROM Employee 125 | WHERE AddressLine NOT IN ('Argentina'); 126 | ``` 127 | 128 | 11. From the following table, write a SQL query to find those employees who EmployeeID's are before 105. Return complete information about the employees. 129 | 130 | ```javascript 131 | SELECT * 132 | FROM Employee 133 | WHERE EmployeeID<('105'); 134 | ``` 135 | 136 | 12. From the following table, write a SQL query to find those employees who EmployeeID's are after 105. Return complete information about the employees. 137 | 138 | ```javascript 139 | SELECT * 140 | FROM Employee 141 | WHERE EmployeeID>('105'); 142 | ``` 143 | 144 | 13. From the following table, write a SQL query to find those employees who EmployeeID's are before or equal to 105. Return complete information about the employees. 145 | 146 | ```javascript 147 | SELECT * 148 | FROM Employee 149 | WHERE EmployeeID<=('105'); 150 | ``` 151 | 152 | 14. From the following table, write a SQL query to find those employees who EmployeeID's are after or equal to 105. Return complete information about the employees. 153 | 154 | ```javascript 155 | SELECT * 156 | FROM Employee 157 | WHERE EmployeeID>=('105'); 158 | ``` 159 | 160 | 15. From the following table, write a SQL query to find those employees who EmployeeID is equal to 105. Return complete information about the employees. 161 | 162 | ```javascript 163 | SELECT * 164 | FROM Employee 165 | WHERE EmployeeID=('105'); 166 | ``` 167 | 168 | 16. From the following table, write a SQL query to find the details of the employee ‘Carol’. 169 | 170 | ```javascript 171 | SELECT * 172 | FROM Employee 173 | WHERE FirstName = 'Carol'; 174 | ``` 175 | 176 | 17. From the following table, write a SQL query to find the FirstName of the employees whose length is six. Return employee FirstName. 177 | 178 | ```javascript 179 | SELECT FirstName 180 | FROM Employee 181 | WHERE length(FirstName)=6; 182 | ``` 183 | 184 | 18. From the following table, write a SQL query to find the details of the employee LastName ‘Santos’. 185 | 186 | ```javascript 187 | SELECT * 188 | FROM Employee 189 | WHERE LastName = 'Santos'; 190 | ``` 191 | 192 | 19. From the following table, write a SQL query to find those employees whose AddressLine is ‘Brazil’. Return complete information about the employees. 193 | 194 | ```javascript 195 | SELECT * 196 | FROM Employee 197 | WHERE AddressLine = 'Brazil'; 198 | ``` 199 | 200 | 20. From the following table, write a SQL query to find those employees whose AddressLine is ‘Argentina’. Return complete information about the employees. 201 | 202 | ```javascript 203 | SELECT * 204 | FROM Employee 205 | WHERE AddressLine = 'Argentina'; 206 | ``` 207 | 208 | 21. From the following table, write a SQL query to find those employees whose AddressLine are either Brazil or Argentina. Return complete information about the employees. 209 | 210 | ```javascript 211 | SELECT * 212 | FROM Employee 213 | WHERE AddressLine IN ('Brazil','Argentina'); 214 | ``` 215 | 216 | 22. From the following table, write a SQL query to find those employees whose AddressLine are either Chile or United States. Return complete information about the employees. 217 | 218 | ```javascript 219 | SELECT * 220 | FROM Employee 221 | WHERE AddressLine IN ('Chile','United States'); 222 | ``` 223 | 224 | 23. From the following table, write a SQL query to find those employees whose AddressLine begin's with C. Return complete information about the employees. 225 | 226 | ```javascript 227 | SELECT * 228 | FROM Employee 229 | WHERE AddressLine LIKE 'C%'; 230 | ``` 231 | 232 | 24. From the following table, write a SQL query to find those employees whose AddressLine ends with l. Return complete information about the employees. 233 | 234 | ```javascript 235 | SELECT * 236 | FROM Employee 237 | WHERE AddressLine LIKE '%l'; 238 | ``` 239 | 240 | 25. From the following table, write a SQL query to find those employees whose AddressLine values with 'rg' in between. Return complete information about the employees. 241 | 242 | ```javascript 243 | SELECT * 244 | FROM Employee 245 | WHERE AddressLine LIKE '%rg%'; 246 | ``` 247 | 248 | # LICENSE 249 | This assignment is under MIT license. 250 | -------------------------------------------------------------------------------- /employee.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE testdb; /* create database */ 2 | 3 | SHOW CREATE DATABASE testdb; /* reviews the existing created database */ 4 | 5 | USE testdb; /* select the newly database created by USE command */ 6 | 7 | CREATE TABLE Employee 8 | ( 9 | EmployeeID int, 10 | FirstName varchar(255), 11 | LastName varchar(255), 12 | Email varchar(255), 13 | AddressLine varchar(255), 14 | City varchar(255) 15 | ); 16 | 17 | INSERT INTO Employee (EmployeeID, FirstName, LastName, Email, AddressLine, City) 18 | VALUES ('101', 'Lucas', 'Santos', 'lucassantos@gmail.com', 'Brazil', 'Sao Paulo'), 19 | ('102', 'Carlos', 'Santiago', 'carlossantiago@gmail.com', 'Argentina', 'Buenos Aires'), 20 | ('103', 'Emanuel', 'DaSilva', 'emanueldasilva@gmail.com', 'Brazil', 'Rio Grande do Sul'), 21 | ('104', 'Abril', 'Rodriguez', 'abrilrodrigues@gmail.com', 'Argentina', 'Mendoza'), 22 | ('105', 'Carolina', 'Bentresca', 'carolinabentresca@gmail.com', 'Chile', 'Concepsion'), 23 | ('106', 'Carol', 'Santos', 'carolsantos@gmail.com', 'Chile', 'Santiago'), 24 | ('107', 'Gabriela', 'Lopez', 'Gabrielalopez@gmail.com', 'Brazil', 'Amazonas'), 25 | ('108', 'Michael', 'DeCarvalho', 'michaeldecarvalho@gmail.com', 'Brazil', 'Fortaleza'), 26 | ('109', 'George', 'Spencer', 'georgespencer@gmail.com', 'United Kingdom', 'London'), 27 | ('110', 'Christina', 'Diemert', 'christinadiemert@gmail.com', 'United States', 'California'); 28 | 29 | /* 1. From the following table return complete information about the employees */ 30 | SELECT * FROM Employee; 31 | 32 | /* 2. From the following table, write a SQL query to find the cities of all employees. Return city. */ 33 | 34 | SELECT City FROM Employee; 35 | 36 | /* 3. From the following table, write a SQL query to find the unique addressline of the employees. Return addressline. */ 37 | 38 | SELECT DISTINCT AddressLine 39 | FROM Employee; 40 | 41 | /* 4. From the following table, write a SQL query to return EmployeeID, FirstName, LastName, City and AddressLine. */ 42 | 43 | SELECT EmployeeID, 44 | FirstName, 45 | LastName, 46 | City, 47 | AddressLine 48 | FROM Employee; 49 | 50 | /* 5. From the following table, write a SQL query to count the number of characters except the spaces for each FirstName. Return FirstName length. */ 51 | 52 | SELECT length(trim(FirstName)) 53 | FROM Employee; 54 | 55 | /* 6. From the following table, write a SQL query to count the number of characters except the spaces for each LastName. Return LastName length. */ 56 | 57 | SELECT length(trim(LastName)) 58 | FROM Employee; 59 | 60 | /* 7. From the following table, write a SQL query to find the EmployeeID, FirstName, Email of all the employees. */ 61 | 62 | SELECT EmployeeID, 63 | FirstName, 64 | Email 65 | FROM Employee; 66 | 67 | /* 8. From the following table, write a SQL query to find the unique AddressLine with LastName. Return AddressLine and LastName */ 68 | 69 | SELECT DISTINCT AddressLine, LastName 70 | FROM Employee; 71 | 72 | /* 9. From the following table, write a SQL query to find those employees who do not belong to AddressLine Brazil. Return complete information about the employees. */ 73 | 74 | SELECT * 75 | FROM Employee 76 | WHERE AddressLine NOT IN ('Brazil'); 77 | 78 | /* 10. From the following table, write a SQL query to find those employees who do not belong to AddressLine Argentina. Return complete information about the employees. */ 79 | 80 | SELECT * 81 | FROM Employee 82 | WHERE AddressLine NOT IN ('Argentina'); 83 | 84 | /* 11. From the following table, write a SQL query to find those employees who EmployeeID's are before 105. Return complete information about the employees */ 85 | 86 | SELECT * 87 | FROM Employee 88 | WHERE EmployeeID<('105'); 89 | 90 | /* 12. From the following table, write a SQL query to find those employees who EmployeeID's are after 105. Return complete information about the employees */ 91 | 92 | SELECT * 93 | FROM Employee 94 | WHERE EmployeeID>('105'); 95 | 96 | /* 13. From the following table, write a SQL query to find those employees who EmployeeID's are before or equal to 105. Return complete information about the employees */ 97 | 98 | SELECT * 99 | FROM Employee 100 | WHERE EmployeeID<=('105'); 101 | 102 | /* 14. From the following table, write a SQL query to find those employees who EmployeeID's are after or equal to 105. Return complete information about the employees */ 103 | 104 | SELECT * 105 | FROM Employee 106 | WHERE EmployeeID>=('105'); 107 | 108 | /* 15. From the following table, write a SQL query to find those employees who EmployeeID is equal to 105. Return complete information about the employees */ 109 | 110 | SELECT * 111 | FROM Employee 112 | WHERE EmployeeID=('105'); 113 | 114 | /* 16. From the following table, write a SQL query to find the details of the employee ‘Carol’. */ 115 | 116 | SELECT * 117 | FROM Employee 118 | WHERE FirstName = 'Carol'; 119 | 120 | /* 17. From the following table, write a SQL query to find the FirstName of the employees whose length is six. Return employee FirstName. */ 121 | 122 | SELECT FirstName 123 | FROM Employee 124 | WHERE length(FirstName)=6; 125 | 126 | /* 18. From the following table, write a SQL query to find the details of the employee LastName ‘Santos’. */ 127 | 128 | SELECT * 129 | FROM Employee 130 | WHERE LastName = 'Santos'; 131 | 132 | /* 19. From the following table, write a SQL query to find those employees whose AddressLine is ‘Brazil’. Return complete information about the employees. */ 133 | 134 | SELECT * 135 | FROM Employee 136 | WHERE AddressLine = 'Brazil'; 137 | 138 | /* 20. From the following table, write a SQL query to find those employees whose AddressLine is ‘Argentina’. Return complete information about the employees. */ 139 | 140 | SELECT * 141 | FROM Employee 142 | WHERE AddressLine = 'Argentina'; 143 | 144 | /* 21. From the following table, write a SQL query to find those employees whose AddressLine are either Brazil or Argentina. Return complete information about the employees. */ 145 | 146 | SELECT * 147 | FROM Employee 148 | WHERE AddressLine IN ('Brazil','Argentina'); 149 | 150 | /* 22. From the following table, write a SQL query to find those employees whose AddressLine are either Chile or United States. Return complete information about the employees. */ 151 | 152 | SELECT * 153 | FROM Employee 154 | WHERE AddressLine IN ('Chile','United States'); 155 | 156 | /* 23. From the following table, write a SQL query to find those employees whose AddressLine begin's with C. Return complete information about the employees. */ 157 | 158 | SELECT * 159 | FROM Employee 160 | WHERE AddressLine LIKE 'C%'; 161 | 162 | /* 24. From the following table, write a SQL query to find those employees whose AddressLine ends with l. Return complete information about the employees. */ 163 | 164 | SELECT * 165 | FROM Employee 166 | WHERE AddressLine LIKE '%l'; 167 | 168 | /* 25. From the following table, write a SQL query to find those employees whose AddressLine values with 'rg' in between. Return complete information about the employees. */ 169 | 170 | SELECT * 171 | FROM Employee 172 | WHERE AddressLine LIKE '%rg%'; 173 | 174 | --------------------------------------------------------------------------------