<?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>Forem: Durgesh Mahajan</title>
    <description>The latest articles on Forem by Durgesh Mahajan (@durgeshm01722).</description>
    <link>https://forem.com/durgeshm01722</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%2F754751%2F7219366d-edbd-422d-a3d4-c37c0b9679fa.jpg</url>
      <title>Forem: Durgesh Mahajan</title>
      <link>https://forem.com/durgeshm01722</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/durgeshm01722"/>
    <language>en</language>
    <item>
      <title>SQL Beginner Friendly Cheatsheet</title>
      <dc:creator>Durgesh Mahajan</dc:creator>
      <pubDate>Sun, 23 Jan 2022 14:18:29 +0000</pubDate>
      <link>https://forem.com/durgeshm01722/sql-beginner-friendly-cheatsheet-3nm7</link>
      <guid>https://forem.com/durgeshm01722/sql-beginner-friendly-cheatsheet-3nm7</guid>
      <description>&lt;h2&gt;
  
  
  1. Retrieving/Selecting Data -
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;SELECT&lt;/code&gt; statement is used to select data from a database.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;for eg -&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;





&lt;br&gt;
&lt;h2&gt;
  
  
  2. Selecting All Records/Columns of Data -
&lt;/h2&gt;

&lt;p&gt;The Asterisk(&lt;code&gt;*&lt;/code&gt;) is used to select all records.&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 table_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for eg -&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 Student;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;br&gt;
&lt;h2&gt;
  
  
  3. Selecting Distinct Data -
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;SELECT DISTINCT&lt;/code&gt; statement is used to return only distinct (different) values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT column_name FROM table_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for eg -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT StudentName FROM Student;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;br&gt;
&lt;h2&gt;
  
  
  4. Filtering the Records -
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;WHERE&lt;/code&gt; clause is used to filter records.&lt;br&gt;
It is used to extract only those records that fulfill a specified 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 column_name FROM table_name WHERE condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for eg -&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 Student WHERE Marks&amp;gt;=450;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;br&gt;
&lt;h2&gt;
  
  
  5. Filtering the Records by two or more conditions -
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;WHERE&lt;/code&gt; clause can be combined with &lt;code&gt;AND&lt;/code&gt;, &lt;code&gt;OR&lt;/code&gt;, and &lt;code&gt;NOT&lt;/code&gt; operators.&lt;br&gt;
The &lt;code&gt;AND&lt;/code&gt; and &lt;code&gt;OR&lt;/code&gt; operators are used to filter records based on more than one condition.&lt;br&gt;
The &lt;code&gt;NOT&lt;/code&gt; operator displays a record if the condition(s) is NOT TRUE.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column_name FROM table_name WHERE condition1 AND condition2 OR condition3;
&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;SELECT column_name FROM table_name WHERE NOT condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for eg -&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 Student WHERE Marks&amp;gt;=450 AND Div="A";
&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;SELECT * FROM Student WHERE NOT Marks=500;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;br&gt;
&lt;h2&gt;
  
  
  6. Sorting the Data of Records -
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;ORDER BY&lt;/code&gt; keyword is used to sort the result-set in ascending or descending order.&lt;br&gt;
The &lt;code&gt;ORDER BY&lt;/code&gt; keyword sorts the records in ascending order by default. To sort the records in descending order, use the &lt;code&gt;DESC&lt;/code&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column_name FROM table_name ORDER BY column_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for eg -&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 Student ORDER BY Marks DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;br&gt;
&lt;h2&gt;
  
  
  7. Inserting Data -
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;INSERT INTO&lt;/code&gt; statement is used to insert new records in 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;INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table.&lt;/p&gt;

&lt;p&gt;for eg -&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 Student (StudentName, Class, Div, Marks)
VALUES ("Durgesh", "Second Year", "B", 450);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;br&gt;
&lt;h2&gt;
  
  
  8. Updating Data -
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;UPDATE&lt;/code&gt; statement is used to modify the existing records in a table.&lt;br&gt;
If you omit the &lt;code&gt;WHERE&lt;/code&gt; clause, ALL 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 table_name SET column=value WHERE condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for eg -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPDATE Student SET Marks=440 WHERE StudentName="Durgesh";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;br&gt;
&lt;h2&gt;
  
  
  Follow for more :-)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/durgesh-mahajan-99bab0212/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/durgeshm01722" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.instagram.com/durgeshm01722/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>programming</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
