{"id":25030185,"url":"https://github.com/juliargubolin/sql-learning","last_synced_at":"2026-05-02T03:33:13.159Z","repository":{"id":253327810,"uuid":"839579049","full_name":"JuliarGubolin/sql-learning","owner":"JuliarGubolin","description":"This repository was created in order to insert all the documents, files and notes I took while learning SQL through \"Getting started with SQL\" by Thomas Nield (O'Reilly). I am studing DataScience at UNIVESP (Univesidade Virtual do Estado de São Paulo).","archived":false,"fork":false,"pushed_at":"2024-09-20T23:56:54.000Z","size":2445,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T19:31:27.162Z","etag":null,"topics":["books","database","sql","sqlite"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JuliarGubolin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-07T22:52:38.000Z","updated_at":"2024-09-20T23:56:58.000Z","dependencies_parsed_at":"2024-08-16T00:59:41.053Z","dependency_job_id":"a0aed669-8fe8-4ec1-861d-92297d580b35","html_url":"https://github.com/JuliarGubolin/sql-learning","commit_stats":null,"previous_names":["juliargubolin/sql-learning"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JuliarGubolin/sql-learning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliarGubolin%2Fsql-learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliarGubolin%2Fsql-learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliarGubolin%2Fsql-learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliarGubolin%2Fsql-learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JuliarGubolin","download_url":"https://codeload.github.com/JuliarGubolin/sql-learning/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliarGubolin%2Fsql-learning/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32522247,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["books","database","sql","sqlite"],"created_at":"2025-02-05T21:57:03.384Z","updated_at":"2026-05-02T03:33:13.136Z","avatar_url":"https://github.com/JuliarGubolin.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# LEARNING AND REVIEWING :books:\n\nAs a Data Science student, my primary goal is to understand master SQL. To achieve this, I am reading SQL books, starting with *\"Getting started with SQL\"* by Thomas Nield (O'Reilly). Copyright 2016 Thomas Nield, 978-7-4919-3816-4. Althought I am already familiar with much of the content, I believe it's essential to reinforce some commands, clauses and statements in the language.\n\nBelow, I will summarize the most interesting and useful aspects of each chapter. Additionally, whenever I feel inspired, I plan to create practical exercises to apply my new knowledge.\n\n\u003cimg src=\"Readme_Images/BOOK.jpg\" alt=\"image\" width=\"30%\" height=\"auto\"\u003e\n\n## HOW DID I PRACTICE WHILE STUDYING\n\nSince the book does not include exercises to practice, I downloaded a ready to use database from [SQLite Tutorial](https://www.sqlitetutorial.net/sqlite-sample-database/). I named \"Artist_Employee\", but the original name is \"Chinook\". The SQL file containing the **questions** I created by myself and **answers** is in the folder \"Artists_Employee\" above.\n\n![alt text](Readme_Images/sqlite-sample-database-artists_employee.jpg)\n\n## Chapter 4: `SELECT` COMMAND\n\nThree years ago, at my first graduation, the `SELECT` command was the first command I learned during the subject \"Databases I\". Therefore, this module was easier and familiar for me. Despite that, there were some topics I've never heard about, such as **text concatenation**. This topic is about how you can concatenate informations from diferent colums into one and show them in an expecific way for your user. Let's see an example:\n\nLet's pretend I want to concatenate 2 colums, `CITY` and `STATE`, from a table called `USERS` to show it as an address (`LOCATION`), for example, I could use the symbol bar \"|\":\n\n`SELECT NAME, CITY || ',' || STATE AS LOCATION FROM USERS`\n\nIn the example above, this new column, which concatenates the two other columns, was named `LOCATION`, but it wasn't created as an actual column in the table. It's just to display information.\n\nFor this chapter, the author used the database *Weather_Stations*.\n\n## Chapter 5: `WHERE` COMMAND\n\nFor this chapter, the author used the database *Rexon_Metals*.\n\nThis chapter is full of useful comands and symbols. The most intersting for me was the '%' and '_', linked with the expression `LIKE` string by characters to filter. For example: if I just want the report codes from the column `report_code` of the table `station_data` that starts with 'A' followed by any character.\n\n`SELECT * FROM STATION_DATA  WHERE REPORT_CODE LIKE 'A%'`\n\nAs you have been noticing, I like to manipulate strings.\n\n## Chapter 6: `GROUP BY` AND `ORDER BY` COMMANDS\n\nFor this chapter, the author used the database *Weather_Stations*.\n\nThis chapter has a lot of usefull information that I have never learned before and introduced more than 10 new commands, including aggregate functions and operators llike `DESC` and `DISTINCT`.\n\nEven though there are a lot of information, I am going to start by the command `ORDER BY`, because this was the one I struggled to undertand. It's used to order a set in ascending or decending order (for this last one, you will need to use `DESC` after the column's name).\n\nUsing the database \"Chinook\" from SQLite website, I tried to create questions to answer myself. I am going to write it below, followed by my answer. (More questions in the file)\n\n1.  Is *Purchased AAC media* more used in *Pop* or *Drama* genre?\n\n- Answer: The use of the media is equal for both genres.\n\nSQL Query used:\n\n`select genres.Name, `\n`COUNT(media_types.Name) AS Media_Purchased_AAC_Audio_File FROM genres, media_types `\n`where media_types.Name='Purchased AAC audio file' AND genres.Name IN ('Pop', 'Drama')`\n`GROUP BY genres.Name;`\n\nAs you can see, I needed to learn more contents than I had been leaning until now. But it was really helpful to see beyond the book's content.One important thing I learned from this exercise is that `COUNT()` only works if used with `GROUP BY`.\n\n2.  Show the employees and how many customers they are helping in decending order.\n\n- Answer: code.\n\n`select employees.FirstName || ' ' || employees.LastName AS EMPLOYEE_FULLNAME, `\n`COUNT(customers.SupportRepId) AS How_Many_Costumers_Am_I_Helping `\n`FROM employees, customers `\n`WHERE employees.EmployeeId = customers.SupportRepId `\n`GROUP BY employees.FirstName `\n`ORDER BY employees.FirstName DESC; `\n\nResult table:\n\n![alt text](Readme_Images/image.png)\n\nFrom this question, I learned the importance of follow the SQL commands in the correct sequen\n\n## Chapter 7: `CASE` STATEMENTS\n\nFor this chapter, the author used the database *Weather_Stations*.\n\nSince I have a good knowledge of programming, learn about this topic was easier. CASE statement can filter information, just like `WHERE` command does, but it allow us to be more specific and  make more complex queries. \n\nThe most interesting topic about this chapter was \"Case Zero/Null\", which shows that we can put a whole `CASE` statement inside an agregated function:\n\n`SELECT month,`\n`AVG(CASE WHEN (RAIN OR HAIL) THEN temperature ELSE 0 END) as avg_precipitation_temp,`\n`AVG(CASE WHEN NOT (RAIN OR HAIL) THEN temperature ELSE 0 END) as non_avg_precipitation_temp`\n`FROM station_data`\n`WHERE year \u003e 2000`\n`GROUP BY month`\n\nIn the query above, the aim is to get the average of temperature when it rains or hails and when it does not rain or hail after the year 2000.\n\n## Chapter 8: `JOIN` CLAUSE\n\nThis chapter explain **three types** of JOIN clause: `INNER JOIN`, `LEFT JOIN` and `RIGHT (OUTER) JOIN`. Let's start with `INNER JOIN`. The images illustrating the `JOINS` are from [W3Schools website](https://www.w3schools.com/sql/sql_join.asp).\n\n### 1. `INNER JOIN`\n\n`INNER JOIN` is used to return records that have commom columns in both tables.\n\n![INNER JOIN FROM W3SCHOOLS](Readme_Images/Inner_Join.png)\n\nThis type is used with `FROM` statement and just returns records that exists in both tables. In addiction: `INNER JOIN` does not allow null vales. So, if you want to see NULL values you should use `LEFT JOIN`.\n\nEXAMPLE: shows all customers and your invoices. This two tables are related by the field `CustomerId`.\n\n`SELECT`\n`CUSTOMERS.CustomerId,`\n`FirstName AS CUSTOMER_NAME,`\n`InvoiceId AS ID_ORDER,`\n`Total,`\n`InvoiceDate AS INITIAL_DATE,`\n`COUNT(*) as NUMBER_ORDERS`\n`FROM CUSTOMERS INNER JOIN INVOICES ON CUSTOMERS.CustomerId = INVOICES.CustomerId`\n`GROUP BY CUSTOMERS.CustomerId;`\n\n### 2. `LEFT JOIN`\n\n`LEFT JOIN` is used to return all records from the left table and the records that mached records from the right table. The author recommends to use always `LEFT JOIN` with the table with \"all records\" on the LEFT of the clause because `RIGHT JOIN` is barely used and must be avoided.\n\n![INNER JOIN FROM W3SCHOOLS](Readme_Images/Left_Join.png)\n\n### 3. `RIGHT JOIN` and `OUTER JOIN`\n\nBoth clauses are barely used and SQLite does not support them. Because of that, the book does not show examples of this two clauses.\n\n## Chapter 9: DATABASE DESIGN\n\nThrought this chapter, we are going to build our own database, rather than just manipulating data using queries.\n\nThis database was created by the author to manage a fictional conference called **SurgeTech**. In this fictional scenario, you were tasked by the manager to build a database to handle the attendees, companies, rooms, presentations and attendancees of each presentation. The database schema (made using [Miro](https://miro.com/app/dashboard/) and exacly the same presented in the book) is shown below:\n\n**DATABASE SCHEMA**\n\n\u003cimg src=\"Readme_Images/Database_Schema.png\" alt=\"image\" width=\"60%\" height=\"auto\"\u003e\n\nThese tables and the database were created in SQLite using the interface, as the book taught, but you can use the command `CREATE TABLE` if you want to. So now, the database browser has a database named **SurgeTech_Conference**.\n\nAfter create all the five tables, the book taught how o make associations and how to make foreign keys. So I made it using the instructions. Below, I copied the table used by the author to explain the foreign keys and primary keys and its associations.\n\n| FOREIGN KEY _CHILD TABLE_  | PRIMARY KEY _PARENT TABLE_ |\n| -------- | -------- |\n| PRESENTATION.BOOKED_ROOM_ID  | ROOM.ROOM_ID\n| PRESENTATION_ATTENDANCEE.PRESENTATION_ID | PRESENTATION.PRESENTATION_ID |\n| PRESENTATION_ATTENDANCEE.ATTENDEE_ID   | ATTENDEE.ATENDEE_ID |\n| COMPANY.PRIMARY_CONTATC_ATTENDEE_ID| ATTENDEE.ATTENDEE_ID|\n\n### CREATING VIEWS\n\nThis chapter also shows how to create views. Views are a way to save a often used SQL Query to be easily acessed and executed. The query used to create the firts view is shown below:\n\n`SELECT`\n`COMPANY.NAME AS COMPANY_NAME,`\n`PRESENTATION_ID,`\n`ROOM.ROOM_ID AS ROOM_IDENTIFY`\n`FROM PRESENTATION INNER JOIN COMPANY ON COMPANY.COMPANY_ID = PRESENTATION.BOOKED_COMPANY_ID `\n`INNER JOIN ROOM ON PRESENTATION.BOOKED_ROOM_ID = ROOM.ROOM_ID`\n`GROUP BY PRESENTATION.PRESENTATION_ID`\n\nThis query I made by myself using the instruction presented in the book: \"Show presentation informations with the company's and room's informations\".\n\n## Chapter 10: MANAGING DATA\n\nThis chapter explains the statements `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE TABLE`, `DROP TABLE` and how to `INSERT `and `UPDATE` multiple data.\n\nThe examples in the book are pretty simple. The most interesting topic is about `TRUNCATE TABLE`, which is not supported in SQLite. This statement can delete all the rows in a table, but the `AUTO_INCREMENT` value will be reset to its start number.\n\n## Chapter 11: MOVING FORWARD\n\nThis last chapter aswers teh question: \"Whats comes next?\", listing some books to follow along with SQL, Python, R and more about data science.\n\nI'm not going to write about the Appendix, but I'm studying about the statements commented. Very good book!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliargubolin%2Fsql-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliargubolin%2Fsql-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliargubolin%2Fsql-learning/lists"}