{"id":4502,"date":"2025-06-09T19:45:43","date_gmt":"2025-06-09T10:45:43","guid":{"rendered":"https:\/\/blog.derrylab.com\/?p=4502"},"modified":"2025-06-17T20:00:19","modified_gmt":"2025-06-17T11:00:19","slug":"how-to-learn-sql-in-only-6-minutes","status":"publish","type":"post","link":"https:\/\/blog.derrylab.com\/index.php\/2025\/06\/09\/how-to-learn-sql-in-only-6-minutes\/","title":{"rendered":"How to Learn SQL in Only 10 Minutes"},"content":{"rendered":"\n<p>I used to hate SQL.<br><br>Too many keywords, weird syntax, and you always need some dummy table to even get started. But today, I finally sat down and said: &#8220;Alright. Lets teach myself SQL like I have 10 minutes before a demo.&#8221;<br><br>So here&#8217;s what I learned, I wish someone told me earlier.<br><br>SQL is Just Talking to Tables<br>You can think of it like this:<br>Every SQL command is like telling a robot how to look at a spreadsheet.<br><br>Tables = spreadsheets.<br>Rows = data entries.<br>Columns = fields.<br><br>Simple.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: <code>SELECT<\/code> \u2014 Get Me the Data<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM users;<\/code><\/pre>\n\n\n\n<p>Get <strong>everything<\/strong> from the <code>users<\/code> table.<\/p>\n\n\n\n<p>Want just names?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT name FROM users;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: <code>WHERE<\/code> \u2014 Filter It<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM users WHERE age &gt; 20;<\/code><\/pre>\n\n\n\n<p>Like saying: <em>\u201cShow me users older than 20.\u201d<\/em><\/p>\n\n\n\n<p>You can even combine it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM users WHERE age &gt; 20 AND name != 'Bob';<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: <code>INSERT<\/code> \u2014 Add Data<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO users (name, age) VALUES ('Derry', 25);<\/code><\/pre>\n\n\n\n<p>Adds a row.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Step 4: <code>UPDATE<\/code> \u2014 Change Data<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>UPDATE users SET age = 26 WHERE name = 'Derry';<\/code><\/pre>\n\n\n\n<p>Modify a row. Only works if you <strong>filter<\/strong> with <code>WHERE<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Step 5: <code>DELETE<\/code> \u2014 Remove Data<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>DELETE FROM users WHERE name = 'Derry';<\/code><\/pre>\n\n\n\n<p>Yup. Gone.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Step 6: <code>CREATE TABLE<\/code> \u2014 Make a Table<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE users (\n  id INT,\n  name TEXT,\n  age INT\n);<\/code><\/pre>\n\n\n\n<p>Also: if you screw up\u2026<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DROP TABLE users;<\/code><\/pre>\n\n\n\n<p>Wipes the table.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Step 7: <code>JOIN<\/code> \u2014 Mix Two Tables Together<\/h4>\n\n\n\n<p>Let\u2019s say:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>users<\/code> table: has names and ids<\/li>\n\n\n\n<li><code>orders<\/code> table: has items and user_ids<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT users.name, orders.item\nFROM users\nJOIN orders ON users.id = orders.user_id;<\/code><\/pre>\n\n\n\n<p>Boom. You get people and what they ordered.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Step 8: <code>GROUP BY<\/code> + COUNT<\/h4>\n\n\n\n<p>Count how many orders per user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT user_id, COUNT(*) AS total_orders\nFROM orders\nGROUP BY user_id;<\/code><\/pre>\n\n\n\n<p>Super useful for summaries.<\/p>\n\n\n\n<p>Other similar tricks:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SUM()<\/code> = total value<\/li>\n\n\n\n<li><code>AVG()<\/code> = average<\/li>\n\n\n\n<li><code>MIN()<\/code> \/ <code>MAX()<\/code> = lowest\/highest<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Step 9: <code>LIKE<\/code>, <code>IN<\/code>, <code>BETWEEN<\/code><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM users WHERE name LIKE 'A%';  -- starts with A\nSELECT * FROM users WHERE age BETWEEN 20 AND 30;\nSELECT * FROM users WHERE name IN ('Alice', 'Charlie');<\/code><\/pre>\n\n\n\n<p>Flexible filters. Feels kinda like regex, but friendlier.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Step 10: <code>NULL<\/code> \u2014 It&#8217;s&#8230; Nothing<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM users WHERE email IS NULL;<\/code><\/pre>\n\n\n\n<p>Use <code>IS NULL<\/code> and <code>IS NOT NULL<\/code>.<br>Don\u2019t use <code>= NULL<\/code>. It won&#8217;t work.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Extra Power: Subqueries<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM users\nWHERE id IN (SELECT user_id FROM orders);<\/code><\/pre>\n\n\n\n<p>Yes. SQL can be meta.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Bonus: Try This in Python (with SQLite)<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import sqlite3\nconn = sqlite3.connect(':memory:')\nc = conn.cursor()\n\nc.execute('CREATE TABLE users (id INTEGER, name TEXT, age INTEGER)')\nc.execute(\"INSERT INTO users VALUES (1, 'Alice', 22)\")\nc.execute(\"INSERT INTO users VALUES (2, 'Bob', 30)\")\n\nc.execute(\"SELECT name FROM users WHERE age &gt; 23\")\nprint(c.fetchall())  # &#91;('Bob',)]<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">TL;DR SQL Cheatsheet<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM users;\nINSERT INTO users (name, age) VALUES ('Derry', 25);\nUPDATE users SET age = 26 WHERE name = 'Derry';\nDELETE FROM users WHERE name = 'Derry';\nCREATE TABLE users (id INT, name TEXT, age INT);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Final Thoughts<\/h4>\n\n\n\n<p>I still don\u2019t love SQL. But at least I <em>get it<\/em> now. It\u2019s just talking to a spreadsheet, politely but firmly. Once you learn the verbs (<code>SELECT<\/code>, <code>INSERT<\/code>, <code>UPDATE<\/code>, <code>DELETE<\/code>), it\u2019s just puzzle pieces.<\/p>\n\n\n\n<p>If you&#8217;re like me, coming from Python or anything else, the biggest help was running SQL inside Python (like <code>sqlite3<\/code>) so I could test fast without setting up Postgres or MySQL.<\/p>\n\n\n\n<p>Hope this helps ya! \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I used to hate SQL. Too many keywords, weird syntax, and you always need some dummy table to even get started. But today, I finally sat down and said: &#8220;Alright. Lets teach myself SQL like I have 10 minutes before a demo.&#8221; So here&#8217;s what I learned, I wish someone told me earlier. SQL is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4509,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,5,118],"tags":[254,249,260,255,250,261,257,18,267,246,258,256,251,36,253,266,245,252,244,247,263,262,268,248,265,259,64,264],"class_list":["post-4502","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-programming","category-understanding","tag-backend-development","tag-coding-tutorial","tag-data-analysis","tag-data-science","tag-database","tag-delete-query","tag-developer-guide","tag-development","tag-group-by","tag-insert-query","tag-join-tables","tag-learn-fast","tag-learn-sql","tag-linux","tag-programming","tag-python-sql","tag-relational-database","tag-select-query","tag-sql","tag-sql-basics","tag-sql-crash-course","tag-sql-for-beginners","tag-sql-in-10-minutes","tag-sql-tutorial","tag-sqlite","tag-tech-blog","tag-tutorial","tag-update-query"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2025\/06\/books-bookstore-book-reading-159711.jpeg?fit=1880%2C1250&ssl=1","jetpack-related-posts":[{"id":244,"url":"https:\/\/blog.derrylab.com\/index.php\/2021\/03\/12\/the-riscv-isa-documentation-is-better-than-riscv-green-card\/","url_meta":{"origin":4502,"position":0},"title":"The RISCV ISA Documentation Is Better than RISCV Green Card","author":"derry","date":"March 12, 2021","format":false,"excerpt":"I hosted the RISCV ISA Documentation. This is really helpful if you want to learn about the assembly syntax or learning the RISCV itself. As a beginner, this documentation is more effective instead of constantly checking at the green card. :) RISCV ISA Documentation:https:\/\/blog.derrylab.com\/riscv-isa-documentation You can host it yourself, it\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":100,"url":"https:\/\/blog.derrylab.com\/index.php\/2020\/08\/19\/git-tutorial-how-to-push-to-a-new-repository\/","url_meta":{"origin":4502,"position":1},"title":"GIT Tutorial: How to Push to a New Repository","author":"derry","date":"August 19, 2020","format":false,"excerpt":"Set up your global git configuration first. git config --global user.name \"Your Name\" git config --global user.email \"id@your.site\" If you want to create a new repository: git clone ssh:\/\/id@your.site\/some-repo.git cd some-repo touch README.md git add README.md git commit -m \"add README\" git push -u origin master Or just push the\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":127,"url":"https:\/\/blog.derrylab.com\/index.php\/2020\/11\/17\/how-to-fix-raspberry-pi-ssh-hangs-or-not-responding\/","url_meta":{"origin":4502,"position":2},"title":"How to Fix Raspberry Pi SSH Hangs or Not Responding","author":"derry","date":"November 17, 2020","format":false,"excerpt":"I just set up a Raspberry PI 4 Model B in the laboratory to automatically connect to the lab's router. I found that each random minutes the SSH is hangs and not responding. Adding IPQoS cs0 cs0 line to the end of \/etc\/ssh\/sshd_config file will fix the issue. :)","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":213,"url":"https:\/\/blog.derrylab.com\/index.php\/2021\/09\/27\/git-pristine-how-to-pristine-clean-your-dirty-git-repository\/","url_meta":{"origin":4502,"position":3},"title":"Git Pristine: How to Pristine Clean Your Dirty Git Repository","author":"derry","date":"September 27, 2021","format":false,"excerpt":"I found this command useful and I love this alias! git pristine, a command that will wipe any dirt on your local git copy, any untracked files, and the cache will be removed to make it pristine clean as the remote origin. Now, each time you messed up your repository,\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2021\/09\/pexels-pixabay-48889.jpg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2021\/09\/pexels-pixabay-48889.jpg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2021\/09\/pexels-pixabay-48889.jpg?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2021\/09\/pexels-pixabay-48889.jpg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2021\/09\/pexels-pixabay-48889.jpg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1282,"url":"https:\/\/blog.derrylab.com\/index.php\/2022\/08\/01\/problem-when-building-old-openssl-version-on-the-new-system\/","url_meta":{"origin":4502,"position":4},"title":"Problem When Building Old OpenSSL Version on The New System","author":"derry","date":"August 1, 2022","format":false,"excerpt":"The old OpenSSL seems to have a problem when built using a newer system. I got this problem when compiling OpenSSL 1.1.0f on my Ubuntu 22.04. derry@G14:~\/openssl-1.1.0f$ .\/config -d shared no-asm no-hw Operating system: x86_64-whatever-linux2 \"glob\" is not exported by the File::Glob module Can't continue after import errors at .\/Configure\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/blog.derrylab.com\/index.php\/category\/programming\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/08\/pexels-anamul-rezwan-1145434-scaled.jpg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/08\/pexels-anamul-rezwan-1145434-scaled.jpg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/08\/pexels-anamul-rezwan-1145434-scaled.jpg?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/08\/pexels-anamul-rezwan-1145434-scaled.jpg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/08\/pexels-anamul-rezwan-1145434-scaled.jpg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":2780,"url":"https:\/\/blog.derrylab.com\/index.php\/2023\/04\/25\/how-to-replace-string-in-files-without-text-editor-in-linux\/","url_meta":{"origin":4502,"position":5},"title":"How to Replace String in Files without Text Editor in Linux","author":"derry","date":"April 25, 2023","format":false,"excerpt":"As a Linux user, it's important to know how to modify text files through the command line. One common scenario is changing a single line in a text file, such as enabling or disabling a feature. But what if the OS doesn't have any text editor installed at all? In\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"pencil shavings","src":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2023\/04\/pexels-photo-1237647.jpeg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2023\/04\/pexels-photo-1237647.jpeg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2023\/04\/pexels-photo-1237647.jpeg?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2023\/04\/pexels-photo-1237647.jpeg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2023\/04\/pexels-photo-1237647.jpeg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts\/4502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/comments?post=4502"}],"version-history":[{"count":5,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts\/4502\/revisions"}],"predecessor-version":[{"id":4526,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts\/4502\/revisions\/4526"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/media\/4509"}],"wp:attachment":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/media?parent=4502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/categories?post=4502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/tags?post=4502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}