<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Arthur</title>
    <description>The latest articles on DEV Community by Arthur (@arthurlch).</description>
    <link>https://dev.to/arthurlch</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F442639%2F6909bc80-76e5-4db3-8b9f-0a072e5429dd.jpeg</url>
      <title>DEV Community: Arthur</title>
      <link>https://dev.to/arthurlch</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arthurlch"/>
    <language>en</language>
    <item>
      <title>Simplify Greatest Common Divisor with Euclidean Algorithm</title>
      <dc:creator>Arthur</dc:creator>
      <pubDate>Wed, 13 Sep 2023 15:18:57 +0000</pubDate>
      <link>https://dev.to/arthurlch/simplify-greatest-common-divisor-with-euclidean-algorithm-1lem</link>
      <guid>https://dev.to/arthurlch/simplify-greatest-common-divisor-with-euclidean-algorithm-1lem</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Today I was looking to get the Greatest Common Divisor during a daily LeetCode grind. &lt;/p&gt;

&lt;p&gt;While I used to work with algorithm at work I got rusty and got stuck on a Medium problem where in some step I needed to find the GCD(Greatest Common Divisor). &lt;/p&gt;

&lt;p&gt;So at first let's understand what is a Greatest Common Divisor. &lt;/p&gt;

&lt;h2&gt;
  
  
  GCD
&lt;/h2&gt;

&lt;p&gt;Let's make it very simple, the GCD is the largest number that can evenly divide two or more numbers. &lt;/p&gt;

&lt;p&gt;It's like finding the biggest number that can go into both numbers without leaving any leftovers.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;For 12 and 18, the GCD is 6 because 6 is the largest number that divides both 12 and 18 evenly. Easy right ?&lt;/p&gt;

&lt;p&gt;So the GCD helps us to find a common factor. &lt;/p&gt;

&lt;p&gt;It can also work for strings ! &lt;/p&gt;

&lt;h2&gt;
  
  
  GCG step by step example
&lt;/h2&gt;

&lt;p&gt;Step 1:&lt;br&gt;
  a = 12&lt;br&gt;
  b = 8&lt;br&gt;
  a % b = 4&lt;br&gt;
  (a, b) -&amp;gt; (b, a % b)&lt;/p&gt;

&lt;p&gt;Step 2:&lt;br&gt;
  a = 8&lt;br&gt;
  b = 4&lt;br&gt;
  a % b = 0&lt;br&gt;
  (a, b) -&amp;gt; (b, a % b)&lt;/p&gt;

&lt;p&gt;Step 3:&lt;br&gt;
  a = 4&lt;br&gt;
  b = 0 (termination condition)&lt;/p&gt;

&lt;p&gt;GCD = 4 (the last non-zero remainder)&lt;/p&gt;

&lt;h3&gt;
  
  
  GCD of 2 numbers (TypeScript)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findGCD(a: number, b: number): number {
    // Check conidtion that both numbers are positive
    a = Math.abs(a);
    b = Math.abs(b);

     // This part is the algorthim
    // Use the Euclidean algorithm to find the GCD
    while (b !== 0) {
        const temp = b;
        b = a % b;
        a = temp;
    }

    return a;
}

const num1 = 24;
const num2 = 36;

const gcd = findGCD(num1, num2);
console.log(`The GCD of ${num1} and ${num2} is ${gcd}`);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  GCD for 2 strings (TypeScript)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function gcdOfStrings(str1, str2) {
    // Find the lengths of both strings
    const len1 = str1.length;
    const len2 = str2.length;

    // Calculate the GCD of the lengths using the Euclidean algorithm
    const gcd = (a, b) =&amp;gt; (b === 0 ? a : gcd(b, a % b));
    const lengthGCD = gcd(len1, len2);

    // Extract a substring of lengthGCD from str1
    const x = str1.slice(0, lengthGCD);

    // Check if x divides both str1 and str2
    if (x.repeat(len1 / lengthGCD) === str1 &amp;amp;&amp;amp; x.repeat(len2 / lengthGCD) === str2) {
        return x;
    } else {
        return "";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Also possible to re-use &lt;code&gt;findGCD()&lt;/code&gt; example from above)&lt;/p&gt;

&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Goal
&lt;/h3&gt;

&lt;p&gt;The code's aim is to find the greatest common divisor (GCD) of two strings. In this case, it's not the numerical GCD but rather a string that can be used to construct both &lt;code&gt;str1&lt;/code&gt; and &lt;code&gt;str2&lt;/code&gt; by repeating it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Variables and Functions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;num1&lt;/code&gt; and &lt;code&gt;num2&lt;/code&gt;: Store the lengths of &lt;code&gt;str1&lt;/code&gt; and &lt;code&gt;str2&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gdc(a, b)&lt;/code&gt;: A function to find the GCD of two numbers. This uses the Euclidean algorithm.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;lenGDC&lt;/code&gt;: Stores the GCD of the lengths of the two strings.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;x&lt;/code&gt;: The potential GCD string. It slices &lt;code&gt;str1&lt;/code&gt; up to &lt;code&gt;lenGDC&lt;/code&gt; characters.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Core Logic
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Find the GCD of the lengths of the two strings using &lt;code&gt;gdc(num1, num2)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Take the first &lt;code&gt;lenGDC&lt;/code&gt; characters from &lt;code&gt;str1&lt;/code&gt;. Let's call this string &lt;code&gt;x&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Check if &lt;code&gt;x&lt;/code&gt; can recreate &lt;code&gt;str1&lt;/code&gt; and &lt;code&gt;str2&lt;/code&gt; when repeated certain times (&lt;code&gt;num1 / lenGDC&lt;/code&gt; and &lt;code&gt;num2 / lenGDC&lt;/code&gt; times).&lt;/li&gt;
&lt;li&gt;If yes, return &lt;code&gt;x&lt;/code&gt;. Otherwise, return an empty string.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>algorithms</category>
      <category>typescript</category>
      <category>coding</category>
    </item>
    <item>
      <title>Git Subtree in 1 minute</title>
      <dc:creator>Arthur</dc:creator>
      <pubDate>Wed, 16 Feb 2022 12:44:30 +0000</pubDate>
      <link>https://dev.to/arthurlch/git-subtree-in-1-minute-1k2e</link>
      <guid>https://dev.to/arthurlch/git-subtree-in-1-minute-1k2e</guid>
      <description>&lt;h2&gt;
  
  
  "Git subtree" are often described like a  better Git Sub-module.
&lt;/h2&gt;

&lt;p&gt;Git subtree gives the possibility to nest one repository into another repository. It's very useful to manage dependencies in your project.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modifying content of the module without having another repository.&lt;/li&gt;
&lt;li&gt;Keep your metadata files clean. &lt;/li&gt;
&lt;li&gt;Users don't need to learn specific command to modify modules and files.&lt;/li&gt;
&lt;li&gt;After initializing the subtree, all the code is available in the main tree and subtree.
&lt;/li&gt;
&lt;li&gt;Can create easier workflow. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upstream flow is more difficult to modify.&lt;/li&gt;
&lt;li&gt;Need to use git subtree instead of git merge.&lt;/li&gt;
&lt;li&gt;Potential mistakes while committing and mixing super and sub into commit.&lt;/li&gt;
&lt;li&gt;listing multiples subtree is complicated&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Creating a subtree
&lt;/h3&gt;

&lt;p&gt;To add a subtree you need a repository with at least 1 commit(initial commit).&lt;/p&gt;

&lt;p&gt;Then you can add your subtree like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git subtree add --prefix subtreeDirectory https://github.com/arthurlch/mytree.git master --squash

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we clone this repo --&amp;gt;  &lt;a href="https://github.com/arthurlch/mytree.git"&gt;https://github.com/arthurlch/mytree.git&lt;/a&gt; master branch in subtreeDirectory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pull new commits to the subtree repository
&lt;/h3&gt;

&lt;p&gt;Use pull instead of add. &lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git subtree pull --prefix subtreeDirectory https://github.com/arthurlch/mytree.git master 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  UPDATE
&lt;/h3&gt;

&lt;p&gt;You can update the subtree remote repo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git subtree push --prefix subtreeDirectory https://github.com/arthurlch/mytree.git master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: The commit will be stored in the host repository and with it logs. &lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Subtree &amp;gt; Submodule&lt;/p&gt;

&lt;p&gt;Feel free to @ me on Twitter with your opinion &amp;amp; feedback about my article; Constructive feedback is always welcome.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>git</category>
      <category>devops</category>
    </item>
    <item>
      <title>Knuth Morris Pratt Algorithm</title>
      <dc:creator>Arthur</dc:creator>
      <pubDate>Mon, 29 Nov 2021 02:56:43 +0000</pubDate>
      <link>https://dev.to/arthurlch/knuth-morris-pratt-algorithm-kn0</link>
      <guid>https://dev.to/arthurlch/knuth-morris-pratt-algorithm-kn0</guid>
      <description>&lt;h2&gt;
  
  
  What is the KMP algorithm
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wOxHCBU4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05h7iiphmz9ryg47ri9v.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wOxHCBU4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05h7iiphmz9ryg47ri9v.jpg" alt="Image description" width="600" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The KMP algorithm is used has a &lt;strong&gt;string-matching algorithm&lt;/strong&gt;, if you want to find the starting index m in string S[] that matches the search word W[]. It is very effective to match string pattern and has an O(n) time complexity and worst case scenario O(m) time complexity.&lt;br&gt;
Brute force solutions would be O(n*m) complexity, KMP O(n+m)&lt;/p&gt;

&lt;p&gt;The space complexity is O(m) due to a pre-processing of a function that sets a table. &lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;The first step is to create a table. However before coding the table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanations:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here a table:&lt;br&gt;
i&lt;br&gt;
+---+---+---+---+---+---+---+---+&lt;br&gt;
| a | b | c | a | b | a | b | c |&lt;br&gt;
+---+---+---+---+---+---+---+---+&lt;br&gt;
|   |   |   |   |   |   |   |   |&lt;br&gt;
+---+---+---+---+---+---+---+---+&lt;br&gt;
k&lt;/p&gt;

&lt;p&gt;The first line represents a string and the second line a sub-string(pattern).   &lt;/p&gt;

&lt;p&gt;The first line is called i.&lt;br&gt;
The second line is called k.&lt;/p&gt;

&lt;p&gt;The line i has a recurrent pattern which is abc.&lt;/p&gt;

&lt;p&gt;We can define a pattern as prefix and suffix.&lt;/p&gt;

&lt;p&gt;Prefix : a,ab,abc.&lt;br&gt;
Suffix: c, bc, abc. &lt;/p&gt;

&lt;p&gt;One prefix is matching a suffix: 'abc'.&lt;/p&gt;

&lt;p&gt;If encountering 'abc' twice in a table then:&lt;br&gt;
a: 1, b:2, c:3 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple Table:&lt;/strong&gt;&lt;br&gt;
Pattern: 'aab'&lt;br&gt;
+---+---+---+---+---+---+---+---+&lt;br&gt;
| a | a | b | a | b | a | a | b |&lt;br&gt;
+---+---+---+---+---+---+---+---+&lt;br&gt;
| 0 | 0 | 0 | 1 | 0 | 1 | 2 | 3 |&lt;br&gt;
+---+---+---+---+---+---+---+---+&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complex table&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;+---+---+---+---+---+---+---+---+---+---+&lt;br&gt;
| a | b | c | a | b | a | x | a | b | c |&lt;br&gt;
+---+---+---+---+---+---+---+---+---+---+&lt;br&gt;
| 0 | 0 | 0 | 1 | 2 | 0 | 0 | 1 | 2 | 3 |&lt;br&gt;
+---+---+---+---+---+---+---+---+---+---+&lt;/p&gt;

&lt;p&gt;We have a pattern 'abc'. &lt;br&gt;
Any character that is not included in our pattern will be 0.&lt;br&gt;
Characters included in the pattern('abc') are respectively are index&lt;br&gt;
Index 3,4 'ab' a:1,b:2. &lt;br&gt;
Second match at index 8,9,10 'abc'. a:1,b:2,c:3. &lt;/p&gt;

&lt;p&gt;That's how we define a table to set up the algorithm. We simply match the prefix and suffix from a table and set a value according to the pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding the table
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Table(a) {
  // create an array from index 0
  const table = [0];
  // define i for looping trough table
  // define j = length prefix and suffix
  let i = 1;
  let k = 0;
  while (i &amp;lt; a.length) {
    // if character match them increase i and set k equal to i;
    if (a[i] === a[k]) {
      k += 1;
      table[i] = k;
      i += 1;
    // if k is greater than 0 and  
     characters don't match 
    // will reset k to previous index table -1 then while loop again to compare next i from k 
    } else if (k &amp;gt; 0) {
      k = table[k - 1];
    // no character match and k is equal to 0 then increment i to check the next character
    } else {
      table[i] = 0;
      i += 1;
    }
  }
  return table;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The easiest way to understand how to table is working is to watch the tables above and reading the code at the same time. &lt;/p&gt;

&lt;h2&gt;
  
  
  Finishing the Algorithm
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const strStr = (string, subString) =&amp;gt; {
  // filter out if string is empty = ''
  if (subString === "") return 0;
  // build table from Table function
  const Table = buildTable(subString);
  // create our variable k &amp;amp; i
  i = 0;
  k = 0;
  // we loop trough both string and substring
  while (i &amp;lt; string.length &amp;amp;&amp;amp; j &amp;lt; subString.length) {
    // if characters match, increse index by one for both string and continue looping
    if (string[i] === subString[k]) {
      i += 1;
      k += 1;
      // if no match return k to previous index k -1
    } else if (j &amp;gt; 0) {
      k = buildTable[k - 1];
      // if no match and k = 0, increment
    } else {
      i += 1;
    }
    // when we got sutsring into string return -1
    if (k === subString.length) return i - k;
  }
  return -1;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Bonus naive solution
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function stringSearch(string, pattern) {
  let count = 0;
  for (let i = 0; i &amp;lt; string.length; i++) {
    for (let j = 0; j &amp;lt; pattern.length; j++) {
      if (pattern[j] !== string[i + j]) break;
      if (j === pattern.length - 1) {
        console.log(i)
        count++;  
      } 
    }
  }
  return count;
}

console.log(stringSearch("akgjfjhuyutomatokajkhgsvkjrtomato", "tomato"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You can test your skills for the KMP algorithm with leetcode question n'28. &lt;br&gt;
shorturl.at/bdD35&lt;/p&gt;

&lt;p&gt;Feel free to @ me on Twitter with your opinion &amp;amp; feedback about my article; Constructive feedback is always welcome.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>javascript</category>
      <category>career</category>
      <category>programming</category>
    </item>
    <item>
      <title>Frequency Counter Pattern</title>
      <dc:creator>Arthur</dc:creator>
      <pubDate>Fri, 19 Nov 2021 06:52:22 +0000</pubDate>
      <link>https://dev.to/arthurlch/frequency-counter-pattern-4d63</link>
      <guid>https://dev.to/arthurlch/frequency-counter-pattern-4d63</guid>
      <description>&lt;h2&gt;
  
  
  What is the Frequency Counter Pattern?
&lt;/h2&gt;

&lt;p&gt;It's a pattern that uses Objects, sets to inspect the frequencies of values. &lt;/p&gt;

&lt;p&gt;You want to use this pattern when comparing inputs to multiple data, like [anagrams](&lt;a href="https://en.wikipedia.org/wiki/Anagram"&gt;https://en.wikipedia.org/wiki/Anagram&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It's also useful to avoid quadratic time complexity O(n²) since the Frequency Counter Pattern has a complexity of O(n). &lt;/p&gt;

&lt;h2&gt;
  
  
  Example with squared numbers
&lt;/h2&gt;

&lt;p&gt;One of the easiest examples used to explain the Frequency Counter pattern is creating a function that takes 2 array and compare the values of the arrays. It should return true if the corresponding value squared in the other array. It will return false if the frequency of the values is not the same. &lt;/p&gt;

&lt;p&gt;isSquaredFrequency([1,2,3], [9,1,4]) // True&lt;/p&gt;

&lt;p&gt;Even not in the order each value has its corresponding squared value in the second array.&lt;/p&gt;

&lt;p&gt;isSquaredFrequency([1,3,4], [1,16]) // False&lt;/p&gt;

&lt;p&gt;The value of 3 squared is not in the second array.&lt;/p&gt;

&lt;p&gt;isSquaredFrequency([3,3,2,1], [9,4,4,1]) // False &lt;/p&gt;

&lt;p&gt;The frequency doesn't match since the number 2 is included in the first array, but 2 squared (4) is present twice in the second array. It doesn't match the frequency. &lt;/p&gt;

&lt;h2&gt;
  
  
  Making the isSquaredFrequency Function
&lt;/h2&gt;

&lt;p&gt;isSquaredFrequency() should compare both array length and compare each index.&lt;/p&gt;

&lt;p&gt;To do that we could use a solution with nested loops.&lt;/p&gt;

&lt;p&gt;Therefore nested loop has a quadratic time complexity, so let's use the frequency counter pattern to create our function. &lt;/p&gt;

&lt;p&gt;It's often better to have multiple for loop instead of nested loops. &lt;/p&gt;

&lt;p&gt;If n is  equal to 100 then you loop through n 100 times for each (for loop).&lt;/p&gt;

&lt;p&gt;If n is equal to 100 then you loop through with a nested loop. You will loop n * n times so 100 * 100 = 10,000.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function  isSquareFrequency(arr1,arr2) {
    // compare arrays length
    if(arr1.length !== arr2.length) return false;
    // create 2 counter
    let counter1 = {}
    let counter2 = {}

    // looping through each array x on x times
    // and store the number of time each value appears in the 
    // array
    for (let val of arr1) {
      counter1[val] = (counter1[val] || 0) + 1
    }
    for (let val of arr2) {
      counter2[val] = (counter2[val] || 0) + 1
    }


    // check is there is the value counter1 key squared in the 
    // counter 2, then check if the number of values correspond
    // in the counter1

    for (let key in counter1) {
      if(!(key ** 2 in counter2)) return false;
      if (counter2[key ** 2] !== counter1[key]) return false;
    }
    return true;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let array1 = [1,1,3,3,3] 
let array2 = [1,2,9,9,9]
let array3 = [1,1,9,9,9]

console.log(isSquareFrequency(array1,array2)) // return false
console.log(isSquareFrequency(array1,array3)) // return true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using an object instead of an array we can deconstruct an array, so we can compare other values more easily.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Anagram
&lt;/h2&gt;

&lt;p&gt;Anagrams are one of the most asked questions during interviews, as you can see here: &lt;a href="https://stackoverflow.com/questions/909449/anagrams-finder-in-javascript"&gt;https://stackoverflow.com/questions/909449/anagrams-finder-in-javascript&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The frequency counter pattern can help us to solve this problem in a very elegant way and with O(n) time complexity. &lt;/p&gt;

&lt;h4&gt;
  
  
  Example.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isAnagram(firstString,secondString) {
 // check if both strongs have same length 
  if (firstString.length !== secondString.length) return false; 

  // create object to store the key value of each letter to 
     decompose the string
  let anagram = {}; 

  // loop through the first string and decompose the string into an object
  for (let i = 0; i &amp;lt; firstString.length; i++ ) {
    let char = firstString[i];
    // check if the letter exist and if more than 1 increment the 
    // key/value, if character in anagram is true, add 1, if false 
    // then only 1 character so char = 1 
    anagram[char] ? anagram[char] +1 : anagram[char] = 1; 
  }

  // second loop to go through the second string 
  for (let i = 0; i &amp;lt; secondString.length; i++) {
    let char = secondString[i];
    // check for the letter. if none then false, otherwise 
   // continue looping, 
    if (!anagram[char]) {
      return false;
    } else {
      anagram[char] -= 1;
    }
  }
  return true;
}

console.log(isAnagram('dog','gd')); // false
console.log(isAnagram('cat','tac')); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can decompose the object anagram to see how it looks like.&lt;br&gt;
{d: 1, o: 1, g: 1} &lt;br&gt;
Each time we loop if the character is present, then we subtract the char that match. &lt;/p&gt;

&lt;p&gt;First loop: {d: 0, o: 1, g: 1} &lt;br&gt;
Second loop: {d: 0, o: 0, g: 1} &lt;br&gt;
Third loop: {d: 0, o: 0, g: 0} &lt;/p&gt;

&lt;p&gt;Then will return true.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There are not many resources available about the Frequency Counter Pattern. I invite you to check more about! &lt;/p&gt;

&lt;p&gt;Feel free to @ me on Twitter with your opinion &amp;amp; feedback about my article; Constructive feedback is always welcome.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Polya’s Problem Solving Techniques</title>
      <dc:creator>Arthur</dc:creator>
      <pubDate>Wed, 03 Nov 2021 14:23:04 +0000</pubDate>
      <link>https://dev.to/arthurlch/polyas-problem-solving-techniques-23nc</link>
      <guid>https://dev.to/arthurlch/polyas-problem-solving-techniques-23nc</guid>
      <description>&lt;p&gt;I want to talk about a book that I read long ago about problem solving, problem solving is an important skill for anyone but especially important for developers and engineers!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yMp25nnG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yh9zdo2lxqpm3kv9a0ex.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yMp25nnG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yh9zdo2lxqpm3kv9a0ex.jpg" alt="Image description" width="640" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In 1945 George Polya published a book How To Solve It and sold over one million copies. I'm gonna make a resume and reuse some content from his book, therefore I'll try to summarize everything here! &lt;/p&gt;

&lt;p&gt;Polya identified &lt;strong&gt;4 basic principles&lt;/strong&gt; of problem solving.&lt;/p&gt;

&lt;h2&gt;
  
  
  First Principle: Understand the Problem
&lt;/h2&gt;

&lt;p&gt;First of all a very easy thing to ask yourself is, Do I understand the meaning of the questions/problem.&lt;/p&gt;

&lt;p&gt;• Do you understand all the words used in stating the problem?&lt;br&gt;
• What are you asked to find or show?&lt;br&gt;
• Can you restate the problem in your own words?&lt;br&gt;
• Can you think of a picture or diagram that might help you understand the&lt;br&gt;
problem?&lt;br&gt;
• Is there enough information to enable you to find a solution?&lt;/p&gt;

&lt;h2&gt;
  
  
  Polya’s Second Principle: Devise a Plan
&lt;/h2&gt;

&lt;p&gt;Sun-Tzu said: Plan for what is difficult while it is easy, do what is great while it is small.&lt;/p&gt;

&lt;p&gt;Making a plan is one of the first steps to solve any problems. There is many approach to conceive a successful plan. &lt;/p&gt;

&lt;p&gt;*Guess and check &lt;br&gt;
*Look for a pattern&lt;br&gt;
*Make an orderly list &lt;br&gt;
*Draw a picture&lt;br&gt;
*Eliminate the possibilities &lt;br&gt;
*Solve a simpler problem&lt;br&gt;
*Use symmetry &lt;br&gt;
*Use a model&lt;br&gt;
*Consider special cases &lt;br&gt;
*Work backwards&lt;br&gt;
*Use direct reasoning &lt;br&gt;
*Use a formula&lt;br&gt;
*Solve an equation &lt;br&gt;
*Be ingenious&lt;/p&gt;

&lt;p&gt;My favorites are: Trying to find pattern, going backward, Solve a simpler problem, which means simply dividing a big problem into smaller problems.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RF9c7elU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5hxgunbm3ukmrx5auiat.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RF9c7elU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5hxgunbm3ukmrx5auiat.jpg" alt="Image description" width="750" height="736"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Polya’s Third Principle: Carry Out the Plan
&lt;/h2&gt;

&lt;p&gt;Follow what you planned step by step. During the process patience is important but don't waste time on things that don't work or disturb other parts of your plan. &lt;/p&gt;

&lt;h2&gt;
  
  
  Polya’s Fourth Principle: Look Back
&lt;/h2&gt;

&lt;p&gt;Coming back to our previous steps is the last step.&lt;br&gt;
Taking time to redo, is a simple way to get a better understanding. It's great to summarize what worked and what didn't. &lt;/p&gt;

&lt;h4&gt;
  
  
  1. Understand the Problem
&lt;/h4&gt;

&lt;p&gt;• First. You have to understand the problem.&lt;br&gt;
• What is the unknown? What are the data? What is the condition?&lt;br&gt;
• Is it possible to satisfy the condition? Is the condition sufficient to determine&lt;br&gt;
the unknown? Or is it insufficient? Or redundant? Or contradictory?&lt;br&gt;
• Draw a figure. Introduce suitable notation.&lt;br&gt;
• Separate the various parts of the condition. Can you write them down?&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Devising a Plan
&lt;/h4&gt;

&lt;p&gt;• Find the connection between the data and the unknown. &lt;br&gt;
  Auxiliary problems needs to be considered.&lt;br&gt;
• Have you seen it before? Or have you seen the same problem &lt;br&gt;
  in a slightly different form?&lt;/p&gt;

&lt;p&gt;• Look at the unknown! Try to think of a familiar problem &lt;br&gt;
  having the same or a similar unknown.&lt;br&gt;
• Here is a problem related to yours and solved before. Could &lt;br&gt;
  you use it(StackOverflow, Github)?&lt;/p&gt;

&lt;p&gt;• Could you restate the problem? &lt;br&gt;
• If you cannot solve the proposed problem, try to solve &lt;br&gt;
  first some related problem. &lt;/p&gt;

&lt;p&gt;• Could you imagine a more accessible related problem? &lt;br&gt;
• Could you change the unknown or data, or both if necessary, &lt;br&gt;
  so that the new unknown and the new data are nearer to each &lt;br&gt;
  other?&lt;/p&gt;

&lt;p&gt;• Did you use all the data? Did you use the whole condition? &lt;br&gt;
  Have you taken into account all essential notions involved &lt;br&gt;
  in the problem?&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Carrying Out The Plan
&lt;/h4&gt;

&lt;p&gt;• Third. Carry out your plan.&lt;br&gt;
• Carry out your plan of the solution, check each step. Can you see clearly that the step is correct? Can you prove that it is correct?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9IqmNr43--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/djm8cc0yb45dtp3yhytv.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9IqmNr43--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/djm8cc0yb45dtp3yhytv.jpeg" alt="Image description" width="225" height="225"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h4&gt;
  
  
  4. Looking Back
&lt;/h4&gt;

&lt;p&gt;• Examine the solution obtained.&lt;br&gt;
• Can you check the result? Can you check the argument?&lt;br&gt;
• Can you derive the solution differently? Can you see it at a glance?&lt;br&gt;
• Can you use the result, or the method, for some other problem?&lt;/p&gt;

&lt;p&gt;I really recommend you to read How to Solve It: A New Aspect of Mathematical Method. &lt;/p&gt;

&lt;p&gt;Credits to berkeley who published for free another resume of Polya works, which inspired me to do this one.&lt;br&gt;
&lt;a href="https://math.berkeley.edu/%7Egmelvin/polya.pdf"&gt;https://math.berkeley.edu/~gmelvin/polya.pdf&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Time to solve your fizzbuzz issue with Polya's help&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Feel free to @ me on Twitter with your opinion &amp;amp; feedback about my article; Constructive feedback is welcome.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>test</category>
    </item>
    <item>
      <title>Building my own bug-tracker</title>
      <dc:creator>Arthur</dc:creator>
      <pubDate>Tue, 19 Oct 2021 13:38:23 +0000</pubDate>
      <link>https://dev.to/arthurlch/building-my-own-bug-tracker-4ehe</link>
      <guid>https://dev.to/arthurlch/building-my-own-bug-tracker-4ehe</guid>
      <description>&lt;h2&gt;
  
  
  The idea.
&lt;/h2&gt;

&lt;p&gt;EDIT: Before you start reading, I'm taking an undefined break with this project but will return to it.&lt;/p&gt;

&lt;p&gt;As a developer I always wanted to build my own tools, for the principle to understand how these tools works.&lt;/p&gt;

&lt;p&gt;After a 5 minute brainstorming I decided to make my own BugTracker.&lt;/p&gt;

&lt;p&gt;There is diverse solutions for bug tracking: GitHub issues, Bug Tracker. &lt;br&gt;
I don't like GitHub issues much, it's too simple and there is no predefined template, it's hard at the first glance to understand the importance of the issue without a proper template or system. &lt;/p&gt;

&lt;p&gt;Bug Tracker software are great but I couldn't find a simple one with a modern design except the one from Zoho. They are more enterprise focused software and also most of them are not open source. &lt;/p&gt;

&lt;p&gt;Here 2 list of most known bug tracker &lt;br&gt;
&lt;a href="https://medevel.com/19-os-bug-and-issues-tracking-and-management-solutions" rel="noopener noreferrer"&gt;https://medevel.com/19-os-bug-and-issues-tracking-and-management-solutions&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.guru99.com/top-20-bug-tracking-tools.html" rel="noopener noreferrer"&gt;https://www.guru99.com/top-20-bug-tracking-tools.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;None of them we're what I wanted so I simply decided to make mine!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1633590261938%2FoITa14DW3.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1633590261938%2FoITa14DW3.jpeg" alt="catcoding2.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Stack brainstorming
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Architecture.
&lt;/h3&gt;

&lt;p&gt;Rails monolith.&lt;/p&gt;

&lt;h3&gt;
  
  
  Client side.
&lt;/h3&gt;

&lt;p&gt;I'm used to React but recently tried Vue and felt in love with.&lt;br&gt;
I'm not familiar with Vue that much also I don't know Composition API yet nor VueX. Since I'm not familiar with Vue I decided to go for classic react with Webpack. I also decided to go with simple JS not TS. (Loving TS tho)&lt;/p&gt;

&lt;p&gt;For styling I really like Tailwind but since I'm used to Bootstrap and MaterialUI I decided to stick with Material UI. MUI will be my pick. &lt;/p&gt;

&lt;p&gt;I decided to not use Jest or any TDD tools for the client since I wanna ship it as soon as possible. &lt;/p&gt;

&lt;p&gt;For front-end tooling webpack is by default with Rails which I'm not a huge fan especially since I discovered Vite which I'm in love with.&lt;/p&gt;

&lt;h3&gt;
  
  
  Backend :
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1633594754642%2FzS5rfxNj_.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1633594754642%2FzS5rfxNj_.jpeg" alt="backendmemes.jpg"&gt;&lt;/a&gt; 'credit to @CodeDoesMeme on Twitter'&lt;/p&gt;

&lt;p&gt;Well here things get complicated... &lt;/p&gt;

&lt;p&gt;I'd like to ship my backend asap and not adding to much complexity with DB request, long configuration setup, multiple stack, non native ORM etc&lt;br&gt;
I like JAMStack but it seems to add some complexity and to be useful when you need to scale or are very comfortable with a stack. &lt;br&gt;
Adonis could do the job and seems to be very interesting but I never tried it, so I'm not gonna use any NodeJS framework. &lt;/p&gt;

&lt;p&gt;Other than JAMStack I like Flask and Ruby On Rails, both do a different job and are well known and solid techs. &lt;/p&gt;

&lt;p&gt;Both of them have a huge ecosystem but in my case it seems that Ruby On Rails will be the best choice.&lt;/p&gt;

&lt;p&gt;It's well documented, Ruby's syntax is an eyes treat, MVC pattern which i'm used too, Active Records, Native ORM, Postgre which is to me one the best relational DB and fits my need for this project, gem ecosystem(package sys) is rock solid. &lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment:
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Client side:
&lt;/h3&gt;

&lt;p&gt;Is a no brainer choice, Netlify &amp;lt;3. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1633593901082%2FpzgqbMrWv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1633593901082%2FpzgqbMrWv.png" alt="awsmeme.png"&gt;&lt;/a&gt; 'credit to u/donjuan26 from reddit'&lt;/p&gt;

&lt;h3&gt;
  
  
  Backend:
&lt;/h3&gt;

&lt;p&gt;**Heroku: **Pricey but very straightforward. Maybe&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;VPS + Capistrano:&lt;/strong&gt; Great but require set up &amp;amp; administration of the server. No&lt;/p&gt;

&lt;p&gt;**Single Server: **DigitalOcean/Linode 5$ droplet + Dokku is very easy to deploy and cheap. Scaling is a big ? tho. Maybe&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kuberneters:&lt;/strong&gt; Great tool but overpowered for this project. No&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AWS Elastic Bean:&lt;/strong&gt; Cheap, very Good support &amp;amp; service but AWS pricing system is an unsolved mystery and will probably remain unsolved till human reach a 400 IQ. Good when you need to scale mostly.&lt;/p&gt;

&lt;p&gt;I'm still divided between Heroku and DigitalOcean droplet + Dokku. I might push to prod with Heroku at first with the free tier then go for the Droplet. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Time to code, I will regularly post the process.&lt;/p&gt;

&lt;p&gt;Feel free to @ me on Twitter with your opinion &amp;amp; feedback about my article; It's the first Constructive feedback is welcome.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Get started with MySQL | Mini-Guide</title>
      <dc:creator>Arthur</dc:creator>
      <pubDate>Mon, 14 Sep 2020 07:16:10 +0000</pubDate>
      <link>https://dev.to/arthurlch/get-started-with-mysql-mini-guide-deg</link>
      <guid>https://dev.to/arthurlch/get-started-with-mysql-mini-guide-deg</guid>
      <description>&lt;h2&gt;
  
  
  A QUICK REMINDER
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What's a database ?
&lt;/h3&gt;

&lt;p&gt;A database is an organized collection of data, usually stored and accessed electronically from a computer system. When databases are more complex, they are often developed using formal design and modeling techniques.&lt;/p&gt;

&lt;p&gt;A database will simply record data for us. With a database, you can create data, read data, update data and delete data, etc.&lt;br&gt;
For example, when you are shopping on Amazon, all the items you have seen are saved in a database referencing Amazon items and it is a huge database. A database is a container of data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599635118140%2FKLclSZ5go.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599635118140%2FKLclSZ5go.png" alt="databaseEasy.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is basically 2 types of database where you will see the word SQL : &lt;strong&gt;SQL&lt;/strong&gt;, &lt;strong&gt;NoSQL&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SQL&lt;/strong&gt; databases are relational database.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SQL database will scale vertically.&lt;/li&gt;
&lt;li&gt;They use structured query language. &lt;strong&gt;A Structured Query Language is a language created to manage data  inside a Database Management System&lt;/strong&gt;, like MySQL for example. &lt;/li&gt;
&lt;li&gt;SQL database use tables with rows and columns. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;NoSQL&lt;/strong&gt; databases are non-relational.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NoSQL scale horizontally. &lt;/li&gt;
&lt;li&gt;They have a dynamic schema for unstructured data.&lt;/li&gt;
&lt;li&gt;NoSQL databases are document, key-value, graph etc..&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  What is MySQL
&lt;/h2&gt;

&lt;p&gt;MySQL is a fully managed database service using the query language known as ** SQL **. If you've never heard of MySQL, I recommend you take a look at their &lt;a href="https://www.mysql.com/" rel="noopener noreferrer"&gt;homepage&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Database management systems are very important, they will help us to: manage security, import and export data, manage a larger set of data and allow us to interact with other software applications such as a language of programming. MySQL is probably the most well-known database management system.&lt;/p&gt;

&lt;p&gt;Using SQL / MySQL, we will be able to perform different types of actions and queries in the database.&lt;br&gt;
The different types of actions are sometimes called ** CRUD **.&lt;/p&gt;
&lt;h2&gt;
  
  
  WHAT IS CRUD
&lt;/h2&gt;

&lt;p&gt;CRUD means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Create&lt;/strong&gt; &lt;strong&gt;Read&lt;/strong&gt; &lt;strong&gt;Update&lt;/strong&gt; &lt;strong&gt;Delete&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
These are the four most basic functions that you will perform in a database system.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;*&lt;em&gt;For example: &lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Creating a user account.&lt;br&gt;&lt;br&gt;
Accessing an user account.&lt;br&gt;&lt;br&gt;
Updating a user profile picture.&lt;br&gt;&lt;br&gt;
Deleting a old profile picture.   &lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  MySQL Download and installation
&lt;/h2&gt;

&lt;p&gt;Let's download and install MySQL, since the &lt;strong&gt;MySQL documentation&lt;/strong&gt; is very good, we will use it.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Windows
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.mysql.com/downloads/mysql/" rel="noopener noreferrer"&gt;Download&lt;/a&gt;  &amp;amp; &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/windows-installation.html#:~:text=The%20simplest%20and%20recommended%20method,%2Finstaller%2F%20and%20execute%20it." rel="noopener noreferrer"&gt;Install&lt;/a&gt; &lt;/p&gt;
&lt;h3&gt;
  
  
  MacOS
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.mysql.com/downloads/mysql/" rel="noopener noreferrer"&gt;Download&lt;/a&gt; &amp;amp;  &lt;a href="https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-pkg.html" rel="noopener noreferrer"&gt;Install&lt;/a&gt; .&lt;/p&gt;
&lt;h3&gt;
  
  
  Linux(Ubuntu &amp;amp; Ubuntu based distro)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://support.rackspace.com/how-to/install-mysql-server-on-the-ubuntu-operating-system/" rel="noopener noreferrer"&gt;Download and install &lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599484413628%2FthtsD0ESV.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599484413628%2FthtsD0ESV.jpeg" alt="readthedoc2.jpg"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Let's connect to MySQL &amp;amp; creating a database
&lt;/h2&gt;

&lt;p&gt;You just installed MySQL and ready to dive into SQL.  &lt;/p&gt;

&lt;p&gt;On linux you might need to start SQLService&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service mysql start

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's create a simple MySQL database, we will need to connect to the MySQL server from our command prompt/terminal. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Let's connect as root with the command:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql -u root -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;** Note: A password will be required to connect to the MySQL server**, you had to set-up a password during the installation, if you forgot your password go check the documentation  &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html" rel="noopener noreferrer"&gt;here&lt;/a&gt; .   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We will create a new user:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; create user 'testuser' identified by 'testuser';

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Instead of testuser, you are free to choose any username you want. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Now we can create a new database &lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; create database testdatabase;

mysql&amp;gt; grant all on testdatabase.* to 'testdatabase';

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Instead of testdatabase, you are free to choose any database name you want. &lt;/p&gt;

&lt;p&gt;To be sure that we created a database we can type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; show databases;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should be able to see your database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdatabase       |
+--------------------+

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  First table &amp;amp; queries
&lt;/h2&gt;

&lt;p&gt;A query is a set of statements using SQL, which will search the database management system for the information you are looking for.&lt;/p&gt;

&lt;p&gt;When Googling something you simply perform queries. If you Google space cat, you will get a space cat, it's a search query. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599521401159%2FnOn1WZ5Yb.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599521401159%2FnOn1WZ5Yb.jpeg" alt="spacecat.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With SQL we will be able to make queries to find data in a large sets of data. With MySQL data are stored inside tables.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tables
&lt;/h3&gt;

&lt;p&gt;As mentioned above with MySQL our data are store inside tables, tables contains rows and columns. &lt;br&gt;
Below you can a table that contain 3 columns and 3 rows. &lt;br&gt;
Columns are read vertically.&lt;br&gt;
Rows are read horizontally and contains all the information about an individual or a case. &lt;br&gt;
The row for John would contain: John, 24, 67&lt;/p&gt;

&lt;p&gt;In our table we defined a primary key(colored in pink) which is NAME. A primary key is an attribute which uniquely define a row.&lt;br&gt;
So we can identify more easily each row. &lt;br&gt;
We couldn't have 2 Johns or 2 Katie's but we could have Katie's height equal to John's height since the HEIGHT column is not a primary key and does not need to be unique; In the name, we could only have a single entry.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599526519726%2Fwoa8eMgNM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599526519726%2Fwoa8eMgNM.png" alt="table.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Datatype
&lt;/h3&gt;

&lt;p&gt;Inside our tables we can stock different kind of data, in our example below you can see different data types: strings and integers but table can contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Note: param = parameter &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*&lt;em&gt;String data types:&lt;br&gt;
*&lt;/em&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;CHAR(param) : String with a fixed length that can contain (letters,numbers, special characters) EX: if CHAR(10), CHAR will contain 10 characters and if left empty CHAR will be filled with 10 blank character. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;VARCHAR(param) : String with a variable length that can contain (letters,numbers, special characters) EX: if VARCHAR(10), VARCHAR can contain between 1 and 10 characters. Ex: VARCHAR(40) max number of characters is equal to 40 it's convenient to save space inside your database to limit the number of characters of a string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;BINARY(param) Store binary bytes type, the parameter specifies the column length in bytes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TEXT(param) Store a long string that can hold 21,844 characters.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*&lt;em&gt;Numeric data types:&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;INT(param) : Integer with a range from -9223372036854775808 to 9223372036854775807. Ex: INT(345)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;BIT(param) : Hold a bit value type with a range from 1 to 64. Ex: BIT(32)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;BIGINT(param) :  Big integer with a range from -9223372036854775808 to 9223372036854775807, Ex: BIGINT(3465242552342453)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*&lt;em&gt;Date and Time data types:&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;DATE(param) : Store a date with the format YYYY-MM-DD, EX: DATE("2017-06-15");&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DATETIME(param): Store a date with the time, format YYYY-MM-DD hh:mm:ss. EX: DATETIME("2017-06-15 10:20:45")&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TIME(param): Store the time, format hh:mm:ss. Ex: TIME("10:20:45")&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Creating a table
&lt;/h3&gt;

&lt;p&gt;It's time to create a table using SQL for that we will need an SQL editor.&lt;/p&gt;

&lt;p&gt;Let's download an SQL editor and database manager software called Beekper Studio.  &lt;a href="https://www.beekeeperstudio.io/" rel="noopener noreferrer"&gt;Site&lt;/a&gt; &lt;br&gt;
It's free and  &lt;a href="https://github.com/beekeeper-studio/beekeeper-studio" rel="noopener noreferrer"&gt;open-source &lt;/a&gt; &amp;lt;3 &lt;/p&gt;

&lt;p&gt;Launch the software and click on quick connect, then you'll end up with this window. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599532421170%2FStq7kpyM4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599532421170%2FStq7kpyM4.png" alt="connecttodb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connection type: MySQL &lt;br&gt;
Host: localhost &lt;br&gt;
Port: 3306&lt;br&gt;
User: the username you created.&lt;br&gt;
Password: the password you created before&lt;br&gt;
Default Database: The name of your database, i used testdatabase.&lt;/p&gt;

&lt;p&gt;Before to connect click on Test to see if your credentials are the good one, then let's connect. &lt;/p&gt;

&lt;p&gt;You'll end up on an empty window with a tab query#1, the magic will happens here. &lt;/p&gt;

&lt;p&gt;Before to start check quickly the  &lt;a href="https://docs.beekeeperstudio.io/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;  of Beekeeper Studio.  &lt;/p&gt;

&lt;p&gt;Let's create a new table that describe products from an e-commerce.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE Product (
    product_id INT PRIMARY KEY,
    product_name VARCHAR(40),
    price INT,
    bar_code INT,
    creation_date DATETIME,
    type VARCHAR(40)
);

DESCRIBE product;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go step-by-step: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;CREATE TABLE my_table_name(); will create a table, pretty explicit right? &lt;br&gt;
Note: At the end of each query you should use a ";" semicolon. 1 semicolon = 1 query&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inside the bracket () we will define each columns. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;product_id is the name, INT(integers) is the type of data, PRIMARY KEY define product_id as the primary key of the table. Primary key are unique and very important, choosing an adequate name for the PRIMARY key is important. &lt;/p&gt;

&lt;p&gt;product_name, VARCHAR which is a string and inside the bracket you can specify the number maximum of characters to save space inside the database.&lt;/p&gt;

&lt;p&gt;We repeat the operation every time for each columns; DATETIME(YYYY-MM-DD HH:MM:SS.SSSSS) correspond to a type of data that take  the date and time.   &lt;/p&gt;

&lt;p&gt;Click on your query and then click on the yellow button Run Selection at the bottom right of your editor. &lt;br&gt;
You now created your first table but yet we can't see anything. &lt;/p&gt;

&lt;p&gt;let's run DESCRIBE product to show the table, click on the query and click on Run Selection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DESCRIBE product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you are, we should be able to see our table. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599568916938%2FAlbypfLiz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599568916938%2FAlbypfLiz.png" alt="firstTable.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can see each columns field; Type,(Null: Null mean that the column is not defined, the primary key need to be defined so Null = NO); Default(value), Extra(comments for example) &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Note: SQL Convention
&lt;/h4&gt;

&lt;p&gt;For now we will keep it simple. See CREATE, TABLE, INT,VARCHAR, DATETIME, DESCRIBE. It's the SQL reserved syntax and need to be in CAPITAL letter, it's not necessary and even non-capitalized it will works, it's simply a convention. &lt;/p&gt;

&lt;p&gt;There is a tons of convention for SQL and actually the convention might differ depending of the company/project, the best resource that I found about SQL convention is  &lt;a href="https://www.sqlstyle.guide/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Delete a table
&lt;/h3&gt;

&lt;p&gt;Let's delete our table with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DROP TABLE product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now our table is deleted. Don't delete the previous queries that we wrote. You can 1 query each time, so feel free to delete and re-creating the table.&lt;/p&gt;

&lt;h3&gt;
  
  
  Altering a table
&lt;/h3&gt;

&lt;p&gt;We will use the 'ALTER' statement which is used to delete,add, modify columns in a table. 'ALTER' can also be used to ADD and DROP. &lt;/p&gt;

&lt;p&gt;Let's add a column in our table. &lt;/p&gt;

&lt;p&gt;ALTER TABLE table_name&lt;br&gt;
ADD column_name datatype;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE product
ADD weight INT;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DESCRIBE product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see the new column in the table located at the last position.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599723207293%2FWOocAAaDT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599723207293%2FWOocAAaDT.png" alt="altertable.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's delete the column weight.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE product
DROP COLUMN weight;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's check it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DESCRIBE product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The column has been deleted.&lt;/p&gt;

&lt;p&gt;The 'ALTER' statement is very useful, we also could change the data type of a column like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE product
MODIFY COLUMN bar_code VARCHAR(60);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you run DESCRIBE table_name you should see that bar_code is now a VARCHAR limited to 60 characters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DESCRIBE product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599723638571%2F2RBZ8LEBg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599723638571%2F2RBZ8LEBg.png" alt="bar_code.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Constraints
&lt;/h3&gt;

&lt;p&gt;A SQL constraint is a rule that is specified inside a column. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;PRIMARY KEY&lt;/strong&gt; is a constraint it specify that the column will be a PRIMARY KEY. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;UNIQUE&lt;/strong&gt; It make sure that all values in a column are different. A PRIMARY KEY is also a unique value by default. If you want your value to be UNIQUE in a column, you'll use the constraint UNIQUE.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;FOREIGN KEY&lt;/strong&gt; is a constraint that link a column or a group of columns to another table. It will basically link multiple tables from the specified column with the constraint FOREIGN KEY. The table that contain the FOREIGN KEY is called the child table. The FOREIGN key is a way to link a parent table to a child table. &lt;br&gt;
*&lt;em&gt;With foreign keys, databases can become relational databases.&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will link the column product_name to a child table that we will create but before we need to do something. &lt;br&gt;
When you link two tables with a FOREIGN KEY make sure that the column that will have the FOREIGN KEY constraint is either a PRIMARY KEY or has the constraint UNIQUE. In our case we need to choose a column that will link our 2 tables and modify the column.&lt;/p&gt;

&lt;p&gt;Let's choose  the column: product_name VARCHAR(40)&lt;br&gt;
We need to make this column UNIQUE:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE product
MODIFY COLUMN product_name VARCHAR(40) UNIQUE;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see if your column took the constraint UNIQUE with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DESCRIBE product;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599793122169%2F39_loGlfV.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599793122169%2F39_loGlfV.png" alt="unique.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;in the column key we can see now that the column is having the constraint UNIQUE.&lt;br&gt;
*Note: In my screenshot the VARCHAR is (60) due to a typo, keep (40) like in the code sample above.&lt;/p&gt;

&lt;p&gt;Let's make a child table called product_type and define a FOREIGN KEY.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE product_type (
    category_id INT AUTO_INCREMENT PRIMARY KEY,
    product_name VARCHAR(40),
    sub_category VARCHAR(20),
    FOREIGN KEY (product_name) REFERENCES product(product_name) ON DELETE CASCADE
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599794600151%2FHqaqbyhO2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599794600151%2FHqaqbyhO2.png" alt="childtable.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We define: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A primary key called category_id ( Don't mind the AUTO_INCREMENT)&lt;/li&gt;
&lt;li&gt;A product_name column that will be our foreign key.&lt;/li&gt;
&lt;li&gt;A sub_category column &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then we define the foreign key with this query :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FOREIGN KEY (product_name) REFERENCES product(product_name) 
ON DELETE CASCADE;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;FOREIGN KEY (my_column) REFERENCES parent_table(parent_table_column);&lt;/p&gt;

&lt;p&gt;First you specify FOREIGN KEY in the column that will be the FOREIGN KEY inside the child table (product_type), &lt;br&gt;
REFERENCES the parent table and inside the bracket the (column) you want to link from the parent table. &lt;/p&gt;

&lt;p&gt;The column name in the parent table and in the child table &lt;strong&gt;don't need to have the same&lt;/strong&gt; name but &lt;strong&gt;need to be the same data type&lt;/strong&gt;. You can't link 2 tables with a different type of data, it doesn't make sense and wouldn't work. &lt;/p&gt;

&lt;p&gt;ON DELETE CASCADE  delete means that if a record in the parent table is deleted the linked records in the child table will be deleted. &lt;/p&gt;

&lt;p&gt;ALTER TABLE product&lt;br&gt;
ADD FOREIGN KEY (product_name) REFERENCES product(product_name);&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;NOT NULL&lt;/strong&gt; The column cannot have a null value. When you'll fill the row with data you will need to fill the column with some data, if you tried to let the column without data(null), you won't be able to fill the row with data. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the child table product_type I'd like to make the column sub_category always filled with a value, for this I will need to use the constraint NULL. &lt;/p&gt;

&lt;p&gt;Note: PRIMARY KEY  are NOT NULL by default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE product_type
MODIFY sub_category VARCHAR(20) NOT NULL;

DESCRIBE product_type; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599803854109%2FhxVe1TqBx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599803854109%2FhxVe1TqBx.png" alt="subnull.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the column sub_category, NULL became 'NO' instead of 'YES'. &lt;br&gt;
It means that this column will need to be fill with data when we will fill the table.  &lt;/p&gt;

&lt;p&gt;You can also specify a column with the constraint NOT NULL while creating the table. In fact you can specify in kind of constraint when creating a table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE example_table (
    id INT  PRIMARY KEY,
    name VARCHAR(40) DEFAULT 'User',
    age INT NOT NULL,
        account_creation DATE
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DEFAULT&lt;/strong&gt; gives a default value to the column, above you can see that  name VARCHAR(40) DEFAULT 'User', has the DEFAULT constraint and give to the name column a default value of 'User'. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE example_table
ALTER account_creation SET DEFAULT (2000-01-01);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  AUTO_INCREMENT
&lt;/h4&gt;

&lt;p&gt;Previously you saw AUTO_INCREMENT. It's very a very useful tool, it increment by 1 automatically when a new record is inserted into a table. &lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE animals (
     id MEDIUMINT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
);

INSERT INTO animals (name) VALUES
    ('dog'),('cat'),('penguin'),
    ('lax'),('whale'),('ostrich');

SELECT * FROM animals;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result will be :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+----+---------+
| id | name    |
+----+---------+
|  1 | dog     |
|  2 | cat     |
|  3 | penguin |
|  4 | lax     |
|  5 | whale   |
|  6 | ostrich |
+----+---------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each time we inserted a value inside the column name the id incremented automatically by 1. &lt;/p&gt;

&lt;h2&gt;
  
  
  SQL Syntax and QUERIES
&lt;/h2&gt;

&lt;p&gt;Now you should be able to create and modify tables and specify constraints but yet we didn't inserted data inside our table. &lt;/p&gt;

&lt;p&gt;Let's insert values inside the product table. &lt;/p&gt;

&lt;h4&gt;
  
  
  INSERT INTO
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO product VALUES(1,'TV', 35, 11109474, '2020-01-01 10:10:10');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;INSERT INTO my_table VALUES(id, product_name, price, bar_code, creation_date) &lt;/p&gt;

&lt;p&gt;The INSERT INTO statement is used to insert new data into a database.  &lt;/p&gt;

&lt;p&gt;VALUES() is the place where you will fill the values that you want to put inside your database, they should correspond to the columns you made and to the constraint of the column. &lt;/p&gt;

&lt;p&gt;If i try to insert a product with the same product_name it won't work because the column product_name as a constraint of UNIQUE. &lt;br&gt;
Try it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO product VALUES(2,'TV', 23, 863544, '2020-01-01 10:10:10');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inserting values only in certain columns is also possible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO product (product_id, product_name)
VALUES (7, 'Microwave')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  SELECT
&lt;/h4&gt;

&lt;p&gt;We will need to select values from our database for that we will use the SELECT statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599890798742%2F0Vzdz_cdT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599890798742%2F0Vzdz_cdT.png" alt="selectstatement.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;SELECT * (all) FROM my_table. &lt;/p&gt;

&lt;p&gt;We can also select certain columns from the table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT product_id, price FROM product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here some data for your table product.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO product VALUES(2,'Video-Games', 135, 11103474, '2020-01-01 10:10:10');
INSERT INTO product VALUES(3,'Blue T-Shirt', 14, 11209474, '2020-01-01 10:10:10');
INSERT INTO product VALUES(4,'Asus Computer', 700, 21105474, '2020-01-01 10:10:10');
INSERT INTO product VALUES(5,'Desktop Monitor', 210, 11409474, '2020-01-01 10:10:10');
INSERT INTO product VALUES(6,' Apple Keyboard', 63, 11789474, '2020-01-01 10:10:10');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can be more specific using the WHERE statement. I'd like to select a product where the column is equal to 'video-games'.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM product
WHERE product_name='Video-Games';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599890751237%2FTBFYWm3Vf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599890751237%2FTBFYWm3Vf.png" alt="where.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The query can be even more precise with the AND, OR, NOT statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM product
WHERE NOT product_name='Video-Games' AND NOT product_name ='TV';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will select all the row except the ones where the column product_name contain 'Video-Games' OR product_name ='TV' &lt;/p&gt;

&lt;p&gt;Here what result you should have. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599896815424%2Fk3r8rX1Q_.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599896815424%2Fk3r8rX1Q_.png" alt="orderdesc.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  ORDER BY
&lt;/h4&gt;

&lt;p&gt;We can get the result of a query ordered in a an alphabetic way or numeric with ORDER BY. &lt;/p&gt;

&lt;p&gt;Example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM product
ORDER BY product_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The table is know ordered alphabetically from product_name &lt;/p&gt;

&lt;p&gt;We can also reverse the order with DESC.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM product
ORDER BY product_name DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can specify 2 columns with an ascendant and a descent order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM product
ORDER BY product_name ASC,  product_id DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599899289195%2FOZLWi4Ptx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599899289195%2FOZLWi4Ptx.png" alt="ascdesc.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  MIN() and MAX() with GROUP BY
&lt;/h4&gt;

&lt;p&gt;MIN will return the smallest value in the selected column and MAX will return the largest value. &lt;/p&gt;

&lt;p&gt;If we want to know the most expensive product in the table we could do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT MAX(price)
FROM product; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Return the largest value in price. &lt;/p&gt;

&lt;p&gt;We can return a GROUP, where we find the max value for every group. It's a little confusing so let's try.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT product_id, MAX(price)
FROM product
GROUP BY product_id 
ORDER BY MAX(price);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599980064486%2FH3s3CRlS7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599980064486%2FH3s3CRlS7.png" alt="groupby.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's decompose the QUERY SELECT column, MAX(column) &lt;br&gt;
from table &lt;br&gt;
GROUP BY (first_column shown in the result) &lt;br&gt;
ORDER BY (second_column that you want to be ordered by value)&lt;/p&gt;

&lt;p&gt;It will works the same way with MIN(). &lt;/p&gt;
&lt;h4&gt;
  
  
  IN OPERATOR
&lt;/h4&gt;

&lt;p&gt;IN is an operator useful to specify multiple values with WHERE.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM product
WHERE product_name IN ('TV', 'Video-Games', 'Desktop Monitor');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599981803258%2F8X85muzt6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1599981803258%2F8X85muzt6.png" alt="IN.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  AVG(), SUM(), COUNT()
&lt;/h4&gt;

&lt;p&gt;*&lt;em&gt;COUNT()&lt;br&gt;
*&lt;/em&gt; &lt;br&gt;
Count will return the number of column that match a condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT COUNT(price)
FROM product
WHERE price &amp;lt; 500 ;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Will return the count of all columns that have a price less than 500. &lt;/p&gt;

&lt;p&gt;We used &amp;lt; as an &lt;strong&gt;operator&lt;/strong&gt; but you can also use &lt;strong&gt;&amp;lt;, &amp;gt;, &amp;lt;=, &amp;gt;= ,&amp;lt;&amp;gt;&lt;/strong&gt;(Not equal to). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SUM&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;We could make the sum of the price column.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT SUM(price)
FROM product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also specify a condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT SUM(column)
FROM table
WHERE condition; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;AVG&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;AVG stand for average, let's make the average of the price in the column product.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT AVG(price)
FROM product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also put a condition in your QUERY with WHERE.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT AVG(column)
FROM table
WHERE Condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  LIKE
&lt;/h4&gt;

&lt;p&gt;LIKE is very useful it helps use to find a specified pattern in a column.  &lt;/p&gt;

&lt;p&gt;For example you want to find a certain brand in the product table like an Apple keyboard then we can use LIKE.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM product
WHERE product_name LIKE '%Apple%';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Underscore _ is be used for 1 single character, % sign is used for 0, 1 and multiple characters. &lt;/p&gt;

&lt;h4&gt;
  
  
  UNION
&lt;/h4&gt;

&lt;p&gt;UNION can link 2 results from 2 tables.&lt;/p&gt;

&lt;p&gt;First insert data your child tables with data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO product_type VALUES(2,'Video-Games', 'games');
INSERT INTO product_type VALUES(3,'Blue T-Shirt', 'clothing');
INSERT INTO product_type VALUES(4,'Asus Computer', 'computer');
INSERT INTO product_type VALUES(5,'Desktop Monitor', 'pc monitor');
INSERT INTO product_type VALUES(6,' Apple Keyboard', 'Apple accessories');

SELECT product_name FROM product
UNION
SELECT sub_category FROM product_type
ORDER BY product_name;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We linked the column product_name from the parent table to the column sub_category from the child table.&lt;/p&gt;

&lt;h4&gt;
  
  
  UPDATE
&lt;/h4&gt;

&lt;p&gt;Sometimes you will need to update some data or columns &lt;/p&gt;

&lt;p&gt;You need to use WHERE to specify which row otherwise all the records will be updated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPDATE product
SET product_name = 'Green-shirt', price = 16
WHERE product_id = 3;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  DELETE
&lt;/h4&gt;

&lt;p&gt;We can delete one value at a time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE FROM product WHERE product_name=''Microwave 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's also possible to DELETE all the records and row without deleting the table itself .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE FROM product;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;With all of this you should be able to do some queries, making tables . MySQL is very popular and i encourage to go deeper than this article and to check more about, in the official documentation. I didn't followed the standard convention but you can find more about SQL convention  &lt;a href="https://www.sqlstyle.guide/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
This article cover a very limited part of MySQL but will give you the very basic. It's just the beginning of the journey into DMBS.&lt;/p&gt;

&lt;p&gt;Feel free to @ me on Twitter with your opinion &amp;amp; feedback about my article; &lt;br&gt;
It's the first time that I'm publishing an article be indulgent with your feedback. &lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>mysql</category>
      <category>query</category>
    </item>
  </channel>
</rss>
