<?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: Blackwatch</title>
    <description>The latest articles on DEV Community by Blackwatch (@blackwatch021).</description>
    <link>https://dev.to/blackwatch021</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%2F753337%2F1a960c31-5c88-416d-81b4-aa1c262d5029.jpeg</url>
      <title>DEV Community: Blackwatch</title>
      <link>https://dev.to/blackwatch021</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/blackwatch021"/>
    <language>en</language>
    <item>
      <title>How I Built TERMINAL47: Anonymous Real-Time Chat with Live Translation (Next.js + Socket.io + TypeScript + Express)</title>
      <dc:creator>Blackwatch</dc:creator>
      <pubDate>Mon, 23 Feb 2026 15:59:48 +0000</pubDate>
      <link>https://dev.to/blackwatch021/how-i-built-terminal47-anonymous-real-time-chat-with-live-translation-nextjs-socketio--2973</link>
      <guid>https://dev.to/blackwatch021/how-i-built-terminal47-anonymous-real-time-chat-with-live-translation-nextjs-socketio--2973</guid>
      <description>&lt;p&gt;Zero-friction chat app—no signup, link-only access, anonymous "Agent-X" names, set duration for room, auto room dispose once time is over, no data is saved/stored, pure anonymity, live language switching (history bulk-translates + new messages stream). Hacker terminal UI. V1 complete &lt;a href="https://github.com/BlackWatch021/lingodev_challenge" rel="noopener noreferrer"&gt;github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ovjjemu3j2lh5edvmi9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ovjjemu3j2lh5edvmi9.png" alt=" " width="800" height="375"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Live chat with users sidebar, countdown timer, translation status.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Hey devs!, I wanted to level up my skills, so I combined Socket.io + real-time multilingual chat + cyberpunk UI. Meet TERMINAL47.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Flow:&lt;/strong&gt; Share link → Join as anonymous agent → Chat → Switch English→Japanese mid-convo → All past messages instantly translate → New messages are translated in real time →Timer expires → Room erased forever.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🛠️ Tech Stack (Production Architecture)&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;Frontend: Next.js 16 + TypeScript 
Backend: Express + Socket.io + Lingo.dev SDK
State: useState (local) + localStorage (userName)
Storage: None (pure ephemeral)
Deployment: Local dev → GitHub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 1: Backend Setup (index.js)&lt;/strong&gt;&lt;br&gt;
Clean Express + Socket.io server with dedicated translation endpoints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// index.js
import express from "express";
import { createServer } from "http";
import { Server } from "socket.io";
import socketEvent from "./socket/events.js"; // Room logic here
import languageTranslationBulk from "./utils/translationBulk.js";
import languageTranslationSingle from "./utils/translationSingle.js";

const app = express();
const server = createServer(app);
const io = new Server(server, { cors: { origin: process.env.CLIENT_URL }});

app.use(cors());
app.use(express.json());


app.post("/auth/translation/bulk", async (req, res) =&amp;gt; {
  const { messages, currentLanguage, translateTo } = req.body;
  const languageTranslationFunction = await languageTranslationBulk(
    messages, currentLanguage, translateTo
  );
  res.json({ success: true, data: languageTranslationFunction });
});

app.post("/auth/translation/chunk", async (req, res) =&amp;gt; {
  const { message, currentLanguage, translateTo } = req.body;
  const languageTranslationFunction = await languageTranslationSingle(
    message, currentLanguage, translateTo
  );
  res.json({ success: true, data: languageTranslationFunction });
});

socketEvent(io); // Room management
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Lingo.dev Integration&lt;/strong&gt;&lt;br&gt;
Bulk translation (history on language switch):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// utils/translationBulk.js -
import { LingoDotDevEngine } from "lingo.dev/sdk";

const languageTranslationBulk = async (messages, currentLanguage, translateTo) =&amp;gt; {
  const lingoDotDev = new LingoDotDevEngine({ apiKey: process.env.LINGO_DEV_API_KEY });
  const userMessages = messages.filter((msg) =&amp;gt; msg.text != "");

  const translated = await lingoDotDev.localizeText(userMessages, {
    sourceLocale: currentLanguage,
    targetLocale: translateTo,
  });
  return translated;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Frontend Hook (useChat.ts)&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;// hooks/useChat.ts
export const useChat = () =&amp;gt; {
  const [socket, setSocket] = useState&amp;lt;Socket | null&amp;gt;(null);
  const [roomStatus, setRoomStatus] = useState&amp;lt;boolean | null&amp;gt;(null);
  const [expiresAt, setExpiresAt] = useState&amp;lt;number | null&amp;gt;(null);

  const joinRoom = useCallback((roomId: string, userName: string) =&amp;gt; {
    socket?.emit("join_room", { roomId, userName }, (result: any) =&amp;gt; {
      if (result.success &amp;amp;&amp;amp; result.room) {
        const expiry = Date.now() + result.room.timeRemaining;
        setExpiresAt(expiry);
      }
    });
  }, [socket]);

  const sendMessage = useCallback((roomId: string, message: string) =&amp;gt; {
    socket?.emit("send_message", { roomId, message });
  }, [socket]);

  return { socket, joinRoom, sendMessage, roomStatus, expiresAt };
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: 🔥 Live Translation Magic (Chat.tsx)&lt;/strong&gt;&lt;br&gt;
Hero feature—language switch + bulk/single translation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
  if (!allMessages.length || language === lastLanguage) return;

  setIsTranslating(true);
  const translateChat = async () =&amp;gt; {
    const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/auth/translation/bulk`, {
      method: "POST",
      body: JSON.stringify({
        messages: allMessages,
        currentLanguage: lastLanguage,
        translateTo: language,
      }),
    });
    const data = await response.json();
    setAllMessages(data.data); // All history translated!
  };
  translateChat();
}, [language]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9notctba4ohnjsg6miyy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9notctba4ohnjsg6miyy.png" alt=" " width="800" height="380"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Switch language → History bulk-translates + new messages auto-translate.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: SideNavBar (Users + Timer)&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;// SideNavBar.tsx - Key features
const SideNavBar = ({ userCount, expiresAt, language, setLanguage, isTranslating }) =&amp;gt; {
  const [formattedTime, setFormattedTime] = useState("00:00");

  useEffect(() =&amp;gt; {
    if (!expiresAt) return;
    const tick = () =&amp;gt; {
      const remainingMs = expiresAt - Date.now();
      const totalSeconds = Math.max(0, Math.floor(remainingMs / 1000));
      const minutes = Math.floor(totalSeconds / 60);
      setFormattedTime(`${minutes.toString().padStart(2, '0')}:${(totalSeconds % 60).toString().padStart(2, '0')}`);
    };
    tick();
    const interval = setInterval(tick, 1000);
    return () =&amp;gt; clearInterval(interval);
  }, [expiresAt]);

  return (
    &amp;lt;aside className="w-12 md:w-64 bg-secondaryBackground"&amp;gt;
      &amp;lt;div&amp;gt;USERS- {userCount}&amp;lt;/div&amp;gt;
      &amp;lt;LanguageSelection language={language} setLanguage={setLanguage} /&amp;gt;
      &amp;lt;div className="timer"&amp;gt;{formattedTime}&amp;lt;/div&amp;gt; {/* Red border when &amp;lt;60s */}
    &amp;lt;/aside&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🚀 V1 Complete ✅&lt;/strong&gt;&lt;br&gt;
✅ Real-time chat (Socket.io)&lt;br&gt;
✅ User presence + system messages&lt;br&gt;
✅ Live translation (bulk + streaming)&lt;br&gt;
✅ Room expiry countdown&lt;br&gt;
✅ Hacker terminal UI&lt;br&gt;
✅ Anonymous access (no auth)&lt;br&gt;
✅ TypeScript everywhere&lt;/p&gt;

&lt;p&gt;Next: Typing indicators with Redis V2? Clone the repo and try language switching—feels like magic! 🪄&lt;br&gt;
&lt;a href="https://github.com/BlackWatch021/lingodev_challenge" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>showdev</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>QUICK SQL REVISION</title>
      <dc:creator>Blackwatch</dc:creator>
      <pubDate>Sun, 04 Jan 2026 14:33:01 +0000</pubDate>
      <link>https://dev.to/blackwatch021/quick-sql-revision-2cj9</link>
      <guid>https://dev.to/blackwatch021/quick-sql-revision-2cj9</guid>
      <description>&lt;p&gt;While revising SQL, I realized that I keep making the same notes again and again. So I decided to document everything in one place for quick reference.&lt;/p&gt;

&lt;p&gt;As I was writing, I thought—why not share it as an article? It might help others who are learning SQL or revising for interviews.&lt;/p&gt;

&lt;p&gt;This article covers the core SQL concepts and is intended as a quick revision guide as well as an easy &lt;strong&gt;starting point for beginners&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  SQL
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is SQL?&lt;/strong&gt;&lt;br&gt;
SQL stands for Structured Query Language and is the standard language used to interact with relational databases. It allows us to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create database structures like tables, views, and indexes.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Perform CRUD operations (Create, Read, Update, Delete) on the data stored in those tables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Define permissions and control access to the data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CRUD expands to:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;C – Create&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;R – Read&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;U – Update&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;D – Delete&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What is a database?&lt;/strong&gt;&lt;br&gt;
A database is a structured collection of data stored in a digital system so that it can be efficiently accessed, managed, and updated. It acts as the backbone of most applications because it persists user and system data; without it, most apps would lose their state and real-world usefulness.&lt;br&gt;
Databases are broadly categorized into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Relational databases&lt;/li&gt;
&lt;li&gt;Non-relational (NoSQL) databases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Relational databases&lt;/strong&gt;&lt;br&gt;
In relational databases, data is stored in tables (rows and columns) with a predefined schema. This structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Makes it easier and faster to query data using relationships (joins) between tables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Requires designing the schema up front, so a good understanding of the data model is needed before implementation.&lt;br&gt;
Examples:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MySQL&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PostgreSQL&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SQL Server&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Oracle&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;*Relational databases use SQL as their primary query language&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Non-relational databases&lt;/strong&gt;&lt;br&gt;
Non-relational (NoSQL) databases do not rely on fixed tables and schemas like relational databases. Data can be stored as documents, key–value pairs, wide-column stores, or graphs. This:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Makes it easier and faster to get started because the schema can be more flexible or even schema-less.&lt;/li&gt;
&lt;li&gt;Can become harder to reason about as the data model grows if there is no consistent structure.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can scale very well horizontally for certain workloads, though query patterns and consistency guarantee differ from relational systems.&lt;br&gt;
Examples:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MongoDB (document-based)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Redis (key–value)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cassandra (wide-column)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Data Types&lt;/strong&gt;&lt;br&gt;
Before moving forward, it is important to understand the concept of data types in SQL. Like most programming languages, when creating a table, we must specify the type of each column so the database knows what kind of data it will store and how to validate it.&lt;br&gt;
Data types help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enforce that data is stored in the correct format (numbers, text, dates, etc.).&lt;/li&gt;
&lt;li&gt;Optimize storage and performance by choosing appropriate sizes and representations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Most Common Data Types&lt;/strong&gt;&lt;br&gt;
SQL offers Different Data Types but here we will discuss about most common data types. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. CHAR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CHAR(n) is a fixed-length character type used to store strings with a maximum length of n characters, for example CHAR (21).&lt;/li&gt;
&lt;li&gt;The database reserves space for exactly n characters for each value; if the string is shorter, it may be padded with spaces internally.&lt;/li&gt;
&lt;li&gt;If you try to insert a string longer than n, it will either be truncated or cause an error, depending on the database and settings.
Use cases: values with fixed length such as country codes, status codes, or fixed-format identifiers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. VARCHAR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VARCHAR(n) is a variable-length character type used to store strings up to n characters.&lt;/li&gt;
&lt;li&gt;Unlike CHAR, it only uses as much storage as needed for the actual string plus a small overhead, not the full declared length.&lt;/li&gt;
&lt;li&gt;If a value exceeds the specified maximum length, the database will usually throw an error or truncate based on configuration.
Use cases: general text fields like names, emails, addresses, titles, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. INT&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;INT is used to store whole numbers (integers).&lt;/li&gt;
&lt;li&gt;Exact range depends on the database system and whether it is signed or unsigned, but it typically supports a large range of positive and negative values suitable for IDs, counts, and similar fields.
Use cases: IDs, counts, quantities, ages, and other whole-number values&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. TINYINT&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TINYINT is a smaller integer type with a limited range.&lt;/li&gt;
&lt;li&gt;In MySQL, for example, TINYINT has a range of -128 to 127 when signed, and 0 to 255 when unsigned.&lt;/li&gt;
&lt;li&gt;It is useful when you know values will always remain within a small range, which can save space.
Use cases: small flags, status codes, or compact numeric values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. FLOAT&lt;/strong&gt;    &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FLOAT is a floating-point data type used to store approximate decimal numbers.&lt;/li&gt;
&lt;li&gt;It is called single-precision because it stores numbers using fewer bits, which means less precision compared to DOUBLE.&lt;/li&gt;
&lt;li&gt;In most databases, FLOAT can accurately represent about 6–7 significant digits.&lt;/li&gt;
&lt;li&gt;Because values are stored in binary form, some decimal numbers cannot be represented exactly, which may result in small rounding errors.&lt;/li&gt;
&lt;li&gt;Due to this approximation, FLOAT should not be used for values where exact precision is required (such as money).
Use cases: Measurements, percentages, averages, sensor data, or scientific values where minor rounding differences are acceptable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. DOUBLE&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DOUBLE (or DOUBLE PRECISION) is a floating-point data type used to store approximate decimal numbers with higher precision than FLOAT.&lt;/li&gt;
&lt;li&gt;It uses more bits to store each value, allowing for about 15–16 significant digits of precision in most systems.&lt;/li&gt;
&lt;li&gt;DOUBLE supports a wider range and greater accuracy than FLOAT, making it suitable for more complex calculations.&lt;/li&gt;
&lt;li&gt;Like FLOAT, it still stores values approximately, so exact precision is not guaranteed.
Use Cases: Scientific computations, complex calculations, analytics, and scenarios where higher precision is needed but exact decimal accuracy is not mandatory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;7. Boolean&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Conceptually, a Boolean represents two logical values: true and false.&lt;/li&gt;
&lt;li&gt;Many SQL dialects have a BOOLEAN or BOOL type; however, the actual storage may be implemented internally as a small integer (for example, TINYINT(1) in MySQL).&lt;/li&gt;
&lt;li&gt;In systems that represent Boolean as integers, the common convention is 0 for false and 1 for true.
Use cases: flags like is_active, is_deleted, is_admin, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;8.  DECIMAL / NUMERIC&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DECIMAL (also called NUMERIC in many SQL dialects) is used to store exact decimal numbers.&lt;/li&gt;
&lt;li&gt;Unlike FLOAT and DOUBLE, DECIMAL stores values in base-10, which means decimal numbers are stored exactly as written, without rounding errors.&lt;/li&gt;
&lt;li&gt;DECIMAL (p, s) defines precision (total digits) and scale (digits after decimal).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Rule of thumb:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Use FLOAT/DOUBLE for measurements and calculations, but DECIMAL for money and financial data.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Use cases: Monetary values, prices, salaries, financial calculations, totals, taxes, and any scenario where precision must be exact.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Signed and unsigned integers&lt;/strong&gt;&lt;br&gt;
Sometimes you know a column will never store negative values, such as IDs, counts, or quantities.&lt;br&gt;
• Signed integers can store both negative and positive values (for TINYINT in MySQL: -128 to 127).&lt;br&gt;
• Unsigned integers only store non-negative values but shift the range upward (for TINYINT in MySQL: 0 to 255).&lt;br&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;_id TINYINT UNSIGNED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, _id can only store values from 0 to 255, which is enough for a small set of teacher IDs and saves space compared to a larger integer type.&lt;br&gt;
You can mention that more will be covered under constraints later when you discuss things like NOT NULL, UNIQUE, PRIMARY KEY, and CHECK.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Commands in SQL&lt;/strong&gt;&lt;br&gt;
We know that SQL is a language which is used to interact with database, there are various types of commands with each having its own function, now these commands can be classified into 5 types, and these are –&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. DDL (Data Defining Language)&lt;/strong&gt;&lt;br&gt;
Purpose: Define and manage database structure (tables, schemas).&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CREATE - create tables/databases&lt;/li&gt;
&lt;li&gt;ALTER - modify existing tables&lt;/li&gt;
&lt;li&gt;DROP - delete tables/databases&lt;/li&gt;
&lt;li&gt;TRUNCATE - delete all data (keep structure)&lt;/li&gt;
&lt;li&gt;RENAME - rename objects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. DQL (Data Query Language)&lt;/strong&gt;&lt;br&gt;
This is used to retrieve data from tables. We can apply conditions too, to get specific data.&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SELECT - fetch data with conditions, joins, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. DML (Data Manipulation Language)&lt;/strong&gt;&lt;br&gt;
This is used to manipulate the data present/stored inside the table. We can CRUD operations;&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;INSERT - add new data&lt;/li&gt;
&lt;li&gt;UPDATE - modify existing data&lt;/li&gt;
&lt;li&gt;DELETE - remove data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. DCL (Data Control Language)&lt;/strong&gt;&lt;br&gt;
This is used to grant and revoke permissions to users. As the data grows, we may also add sensitive data in it or there may be data which isn’t needed by one user. So, we can limit what the user is allowed to access to maintain security.&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GRANT - give permissions&lt;/li&gt;
&lt;li&gt;REVOKE - remove permissions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. TCL (Transaction Control Language)&lt;/strong&gt;&lt;br&gt;
One of the most important concepts, although it is used massively in applications. Where it ensures that whole operation is done as per the instructions other wise revert back to the last check point&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BEGIN/COMMIT - save changes&lt;/li&gt;
&lt;li&gt;ROLLBACK - undo changes&lt;/li&gt;
&lt;li&gt;SAVEPOINT - partial rollback points&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Basic Command (Create table)&lt;/strong&gt;&lt;br&gt;
As we know that SQL is a language and everything is done using commands. So here is the most basic command. Which will help us to understand other concepts. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List all Databases&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;SHOW DATABASES;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use a specific database&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;USE database_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;List all tables in current DB&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;SHOW TABLES;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;View table structure&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;DESC table_name
&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;DESC students;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create table (DDL)&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;CREATE TABLE table_name(
   column_1 datatype constraint,
   column_2 datatype constraint,
   column_3 datatype constraint, 
);

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

&lt;/div&gt;



&lt;p&gt;Ex-&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 student(
   Id INT PRIMARY KEY AUTO_INCREMENT,
   first_name VARCHAR(50) NOT NULL,
   last_name VARCHAR(50) NOT NULL,
   phone VARCHAR(15),
   age INT NOT NULL
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;- &lt;br&gt;
&lt;em&gt;Here PRIMARY KEY is a key&lt;br&gt;
AUTO_INCREMENT, NOT NULL are constraints&lt;br&gt;
We will learn about these in future.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyt977zw2vujiygzkdqtj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyt977zw2vujiygzkdqtj.jpg" alt="Table Example" width="800" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DELETE DATABASE/TABLE&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;DROP DATABASE database_name;
&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;DROP TABLE table_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;KEYS&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;PRIMARY KEY (always unique)&lt;/strong&gt;&lt;br&gt;
A column (or set of columns) in a table that uniquely identifies each row (&lt;strong&gt;a unique id&lt;/strong&gt;)&lt;br&gt;
Only one Primary key can be there in a table and it can’t be null.&lt;/p&gt;

&lt;p&gt;Ex-&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 students(
   id INT PRIMARY KEY,
   ……
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;FOREIGN KEY&lt;/strong&gt;&lt;br&gt;
It’s always a good idea to divide data into small tables, rather than keeping everything inside a single table which is a monolith architecture. Now as we divide the tables, we need to establish some sort of relation in between them which allows us to get the data. FOREIGN key in a table refers to the PRIMARY key of another table and helps in establishing that link between tables.&lt;br&gt;
FOREIGN KEY References PRIMARY KEY of another table&lt;br&gt;
A table can have multiple FKs. &lt;br&gt;
Foreign keys may contain null or duplicate values.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parent table = table with PRIMARY KEY&lt;/li&gt;
&lt;li&gt;Child table = table with FOREIGN KEY&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example&lt;br&gt;&lt;br&gt;
A teacher table is in relation with department 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 dept(
   id INT PRIMARY KEY,
   name VARCHAR(50)
);  

CREATE TABLE teacher(
   id INT PRIMARY KEY,
   name VARCHAR(50),
   dept_id INT,

   FOREIGN KEY (dept_id) REFERENCES dept(id);
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here dept is the Parent table while teacher is the Child table (using Foreign Key) and dept_id in teacher table is the FOREIGN KEY, which establishes relation between these two tables. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CASCADE in FOREIGN key&lt;/strong&gt;&lt;br&gt;
FOREIGN key is used to set up relation between tables. Now there may be a need of change in both tables if anything is changed in parent table, for that we use CASCADING &lt;/p&gt;

&lt;p&gt;So, any change(s) in parent table is automatically reflected in children table too.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ON UPDATE CASCADE → Parent ID changes → Child FK updates automatically&lt;/li&gt;
&lt;li&gt;ON DELETE CASCADE → Parent row deleted → Child rows deleted automatically
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE teachers(
   Id INT PRIMARY KEY AUTO_INCREMENT,
   Name VARCHAR(50),
   dept_id INT,

   FOREIGN KEY (dept_id) REFERENCES dept(id)

   ON UPDATE CASCADE
   ON DELETE CASCADE
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;CONSTRAINTS&lt;/strong&gt;&lt;br&gt;
Now let’s talk about &lt;strong&gt;CONSTRAINTS&lt;/strong&gt;, while creating a table we can specify some rules for the columns in the table. Like the values can never be null, we can specify the length, allow duplicate values or not. All these rules are applied using CONSTRAINTS. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some Commonly used CONSTRAINTS&lt;/strong&gt; &lt;br&gt;
&lt;strong&gt;1. NOT NULL&lt;/strong&gt; – This is used to specify that the column can’t be null. There should be a value in it all the time. &lt;br&gt;
&lt;strong&gt;2. UNIQUE&lt;/strong&gt; – In case we want to have unique values in a column, then we use this. &lt;br&gt;
&lt;strong&gt;3. DEFAULT&lt;/strong&gt; – This is used to set a default value, in case no value is provided, then the set default value is used. &lt;br&gt;
&lt;strong&gt;4. CHECK&lt;/strong&gt; - This is used to check or set the permissible value in the column &lt;/p&gt;

&lt;p&gt;Ex.&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 student (
   _id INT PRIMARY KEY,
   first_name VARCHAR (50) NOT NULL,
   last_name VARCHAR (50) NOT NULL,
   phone VARCHAR (15) NOT NULL UNIQUE,
   age INT CHECK (age&amp;gt;=18),
   city DEFAULT 'ABCD'
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;SELECT statement&lt;/strong&gt;&lt;br&gt;
Till now we learned about databases, their types, data types, types of commands, how to create a table, concept of keys and constraints. Now we will dive into the ocean of commands, how we can actually use the commands and play with data and to do so, first and foremost thing we have is the SELECT statement, it is used to retrieve data from the table and return it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT col1, col2, col3 FROM table_name;

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

&lt;/div&gt;



&lt;p&gt;Here the above command will return whole table as the result, * means all. &lt;/p&gt;

&lt;p&gt;Targeting specify column 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;SELECT id, name, city FROM students;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above command will return a table with only id, name and city column.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Column aliases (AS)&lt;/strong&gt;:&lt;br&gt;
In case we want to change “name” to “first_name” in the resultant table, then we can use AS command to do so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT id, name AS first_name, city FROM students;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the resultant table, now the columns will be id, first_name, city. But this won’t affect the actual table in anyways. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CONDITIONS – WHERE clause&lt;/strong&gt;&lt;br&gt;
What if we need specific data from the table, which satisfies certain conditions. To do so, we use WHERE clause with the SELECT statement. WHERE clause allows us to set conditions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT col1, col2, col3, col4…   FROM table_name WHERE condition;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WHERE clause doesn’t work alone, conditions are set with the help of &lt;strong&gt;OPERATORS&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OPERATORS&lt;/strong&gt;&lt;br&gt;
OPERATORS are the backbone of SQL, as they allow us to actually set the conditions as per our requirements. &lt;br&gt;
There are various OPERATORS to choose from, and these are the most commonly and important to know OPERATORS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Arithmetic OPERATORS:  *, -, +, /, %&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;SELECT name, age/2 AS age_divided_by_two FROM students;

SELECT *, age-4 as MINOR FROM students WHERE age-4&amp;lt;18;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Comparison OPERATORS: =, !=, &amp;gt;, &amp;gt;=, &amp;lt;, &amp;lt;=&lt;/strong&gt;&lt;br&gt;
These are used to do comparison&lt;br&gt;
*Note: != means not equal to&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 students WHERE city='New York' AND age&amp;gt;21;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. BITWISE OPERATORS: &amp;amp; (Bitwise AND), | (Bitwise OR)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Logical OPERATORS: AND, OR, NOT, IN, BETWEEN, ALL, LIKE.&lt;/strong&gt;&lt;br&gt;
These are logical in nature&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AND operator&lt;/strong&gt;: This checks if both (right and left) conditions are true, then only it satisfies the conditions.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * from students
WHERE name='John' AND age&amp;gt;26;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;OR operator&lt;/strong&gt;: Similar to AND operator but this checks if either of the conditions is true.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM students
WHERE name='Wick' OR age&amp;gt;50;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;BETWEEN operator&lt;/strong&gt;: Used to set a range for the result.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM students
WHERE marks BETWEEN 80 AND 92;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;IN operator&lt;/strong&gt;: It matches any value specified inside it.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM students
WHERE city IN ('New York', 'Moscow', 'New Delhi')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will only return the rows, where the city is New York, Moscow, or New Delhi only. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;NOT&lt;/strong&gt;: To negate the given condition
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM students
WHERE city NOT IN ('New York', 'Moscow', 'New Delhi')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will return all the rows except the rows where the city is New York, Moscow, or New Delhi&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LIMIT&lt;/strong&gt;: Used to set the limit of returned rows of the table.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM students LIMIT 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now, the result will contain only 5 rows at a time, even if it contains 100 rows. It will only be returning 5 rows at a time. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;OFFSET&lt;/strong&gt;: This one is used to skip certain values and start after them. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;LIMIT&lt;/strong&gt; and &lt;strong&gt;OFFSET&lt;/strong&gt; are used together and these two OPERATORS make pagination in web page possible. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ORDER BY&lt;/strong&gt;: This gives us the facility to sort the result as per our choice. Either Descending or Ascending.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM table_name 
ORDER BY col_name ASC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;&lt;em&gt;ASC= Ascending&lt;br&gt;
DESC= Descending&lt;/em&gt;&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;SELECT * FROM students
WHERE city NOT IN ('Rome', 'Tokyo') 
ORDER BY name DESC
LIMIT 2 OFFSET 2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;AGGREGATE FUNCTIONS&lt;/strong&gt;&lt;br&gt;
These are prebuilt functions/methods which helps us by easing our work, these returns single value as a result.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;COUNT()&lt;/strong&gt;   -  Counts the number of entries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MAX()&lt;/strong&gt;  -  Maximum value in column&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MIN()&lt;/strong&gt;  -  Minimum value in column&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SUM()&lt;/strong&gt;  -  Total sum of values&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AVG()&lt;/strong&gt;  -  Average of values.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Find the max age-&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(age) as MaxAge FROM students;

     OR

SELECT age FROM students ORDER BY age DESC LIMIT 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;GROUP BY clause&lt;/strong&gt; &lt;br&gt;
This is used to group rows that have same values into summary rows. &lt;br&gt;
Generally used with some aggregate function. Both of these goes by hand in hand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT SPID, SUM(amount) 
FROM sales 
GROUP BY SPID 
ORDER BY SPID ASC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;HAVING clause&lt;/strong&gt;&lt;br&gt;
Similar to WHERE clause but used when we want to apply condition after grouping.&lt;br&gt;
It was introduced to address the limitations of WHERE clause, which cannot be used with aggregate functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT city , COUNT(name)
FROM student
GROUP BY city 
HAVING max(marks)&amp;gt;90;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;GENERAL SEQUENCE/ORDER of writing query&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;SELECT columns(s)
FROM   table_Name
WHERE condition
GROUP BY column(s)
HAVING condition
ORDER BY column(s) ASC/DESC
&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 city
FROM   students
WHERE grade='A'
GROUP BY city
HAVING MAX(marks) &amp;gt; 90
ORDER BY city ASC/DESC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;TABLE Related Queries&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1. Create Table&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;CREATE TABLE table_name(
   column_1  datatype constraint,
   column_2  datatype constraint,
   column_3  datatype constraint, 
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ex-&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 student(
   Id INT PRIMARY KEY AUTO_INCREMENT,
   first_name VARCHAR(50) NOT NULL,
   last_name VARCHAR(50) NOT NULL,
   phone VARCHAR(15),
   age INT NOT NULL 
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Insert data&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;INSERT INTO tablename(col1,col2,col3,….) 
VALUES(val1,val2,val3,….);
&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;INSERT INTO students(id,first_name,last_name,phone,age)
VALUES(1, 'John', 'Wick', '7878787878', 35);  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In case you know the order then you may omit the column names&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 students
VALUES(1, 'John', 'Wick', '7878787878', 35);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that we have used AUTO_INCREMENT for id. Which means that the value will increase by its own. To do that, we have to use the columns name and omit the AUTO_INCREMENT column.&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 students (first_name, last_name, phone, age) 
VALUES ('John', 'Wick', '7878787878', 35)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, id will be populated on its own.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insert more than one value/row in table&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;INSERT INTO students(first_name, last_name, phone, age)
VALUES ('John','Wick', '7878787878', 35),
   ('Super', 'Man', '8456985',20),
   ('Bat', 'Man', '2234234',45),
   ('Iron', 'Man', '23584839', 55),
   ('Captain', 'America', '284738473/, 50);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Update table&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;UPDATE table_name 
SET col1=val1 
WHERE condition
&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;UPDATE student 
SET age=44 
WHERE first_name='SUPER';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Delete data&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;DELETE FROM table_name
WHERE condition;
&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;DELETE FROM students 
WHERE first_name= 'Delete';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. ALTER TABLE&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ADD column&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE table_name
ADD COLUMN col_name datatype constraint;
&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;ALTER TABLE students
ADD COLUMN grades VARCHAR(2) NOT NULL;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DROP/DELETE Column&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE table_name
DROP COLUMN column_name;
&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;ALTER TABLE students
DROP COLUMN grades;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;RENAME table&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE table_name
RENAME TO newtable_name;
&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;ALTER TABLE students
RENAME TO newStudents;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CHANGE column&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE table_name
CHANGE COLUMN old_name new_name new_datatype new_constraint;
&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;ALTER TABLE students 
CHANGE COLUMN last_name lastName VARCHAR(20) NOT NULL;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MODIFY column (modify datatype/constraint)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER TABLE table_name
MODIFY col_name new_datatype new_constraint;
&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;ALTER TABLE students
MODIFY phone VARCHAR(15) UNIQUE;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DELETE TABLE data (only table data, not whole table)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUNCATE table_name;
&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;TRUNCATE students;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JOINS&lt;/strong&gt;&lt;br&gt;
One of the most important topics, these are used to combine rows from two or more tables, based on a related column between them. &lt;/p&gt;

&lt;p&gt;Types&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Inner Join&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Outer Join&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Left Join&lt;/li&gt;
&lt;li&gt;Right Join&lt;/li&gt;
&lt;li&gt;Full Join&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. INNER JOIN&lt;/strong&gt;&lt;br&gt;
Returns records that have matching values in both tables (only mutual data is returned)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqb2zm2q8w8wmo0c5940a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqb2zm2q8w8wmo0c5940a.png" alt="Inner join diagram" width="800" height="500"&gt;&lt;/a&gt;&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(s) FROM table_A 
INNER JOIN table_b 
ON tableA.col_name = tableB.col_name;
&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 students
INNER JOIN course
ON student.student_id = course.student_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;This will return only the data which is present in both tables&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OUTER JOINS&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1. LEFT Join&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Returns all records from left table and matched records from the right table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw6kfzcqkbh6nkmdo6mo3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw6kfzcqkbh6nkmdo6mo3.jpg" alt="Outer join diagram" width="724" height="436"&gt;&lt;/a&gt;&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(s)
FROM tableA
LEFT JOIN tableB
ON tableA.col_name = tableb.col_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. RIGHT Join&lt;/strong&gt;&lt;br&gt;
Same as LEFT join, only side changes. This return all records from right table and matched records from left table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh6s6plaf3bou6l8ug0ad.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh6s6plaf3bou6l8ug0ad.jpg" alt="Right join diagram" width="724" height="436"&gt;&lt;/a&gt;&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(s) 
FROM tableA
RIGHT JOIN tableB
ON tableA.col_name = tableb.col_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. FULL Join&lt;/strong&gt;&lt;br&gt;
Returns all records even if there is no relation.&lt;br&gt;
By default, MySQL doesn't support FULL JOIN so we do it through another method and with using UNION.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UNION&lt;/strong&gt;&lt;br&gt;
Helps in combining data and returns unique values only.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FULL JOIN = LEFT JOIN _UNION _RIGHT JOIN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ud33a1fvsgcdsh5ooma.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ud33a1fvsgcdsh5ooma.jpg" alt="Full join diagram" width="724" height="436"&gt;&lt;/a&gt;&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 tableA as A
LEFT JOIN tableB as B
ON A.column = B.column

UNION

SELECT * FROM tableA as A
RIGHT JOIN tableB as B
ON a.column = b.column;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;??Write SQL command to display the left exclusive join: -&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10ljmpklszns04j7obti.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10ljmpklszns04j7obti.jpg" alt="Left exclusive join diagram" width="724" height="436"&gt;&lt;/a&gt;&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 tableA as A
LEFT JOIN tableB as B
ON A.col_name = b.col_name
WHERE b.id IS NULL;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;*Similar for RIGHT exclusive Join.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SELF JOIN&lt;/strong&gt;&lt;br&gt;
A regular join but the table is joined with itself&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(s)
FROM table as A
JOIN table as B
ON A.col_name = B.col_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;UNION&lt;/strong&gt;&lt;br&gt;
Used to combine the result-set of two or more SELECT statements.&lt;br&gt;
Gives unique records.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;*Columns must have similar data types.&lt;/em&gt;&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;SELECT column(s) FROM tableA
UNION
SELECT column(s) FROM tableB;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;We also have UNION all, this allows duplicates on top of UNION's data&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SUBQUERY&lt;/strong&gt;&lt;br&gt;
Subquery or inner query or a nested query is a query within another SQL query. This allows us to do complex operations which isn't or would be hard to do otherwise.&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(s)
FROM table_name
WHERE col_name operator/condition(subquery)
&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 name, marks
FROM student
WHERE marks &amp;gt; (SELECT AVG (marks) FROM student);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;MySQL Views&lt;/strong&gt;&lt;br&gt;
It's a virtual table created from an actual/real table.&lt;br&gt;
Imagine a student table with lots of columns. Now a teacher only needs students roll number, name, marks. Other data isn't needed to the teacher. &lt;/p&gt;

&lt;p&gt;So, a view will be created from the student table which will contain only these columns.&lt;/p&gt;

&lt;p&gt;Although it's a virtual table but it will act just like a real table, operations, select command etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CREATE VIEW&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;CREATE VIEW view_name AS 
SELECT column(s) 
FROM table_name;
&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;CREATE VIEW view1 AS 
SELECT rollno, name, marks 
FROM student


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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;DROP VIEW&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;DROP VIEW view_name;
&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;DROP VIEW view1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>sql</category>
      <category>database</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Wanna know the working of Video calling apps (zoom, google meet, microsoft teams) how they work, here is a quick article on it. What goes behind a video call, how things work, its architecture. Feel free to give it a try😁</title>
      <dc:creator>Blackwatch</dc:creator>
      <pubDate>Thu, 17 Jul 2025 05:51:38 +0000</pubDate>
      <link>https://dev.to/blackwatch021/wanna-know-the-working-of-video-calling-apps-zoom-google-meet-microsoft-teams-how-they-work-2dlp</link>
      <guid>https://dev.to/blackwatch021/wanna-know-the-working-of-video-calling-apps-zoom-google-meet-microsoft-teams-how-they-work-2dlp</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/blackwatch021/webrtc-the-brain-behind-your-virtual-video-calls-1o7" class="crayons-story__hidden-navigation-link"&gt;WebRTC, the Brain Behind Your Virtual Video Calls&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/blackwatch021" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F753337%2F1a960c31-5c88-416d-81b4-aa1c262d5029.jpeg" alt="blackwatch021 profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/blackwatch021" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Blackwatch
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Blackwatch
                
              
              &lt;div id="story-author-preview-content-2694210" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/blackwatch021" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F753337%2F1a960c31-5c88-416d-81b4-aa1c262d5029.jpeg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Blackwatch&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/blackwatch021/webrtc-the-brain-behind-your-virtual-video-calls-1o7" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 16 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/blackwatch021/webrtc-the-brain-behind-your-virtual-video-calls-1o7" id="article-link-2694210"&gt;
          WebRTC, the Brain Behind Your Virtual Video Calls
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webrtc"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webrtc&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/blackwatch021/webrtc-the-brain-behind-your-virtual-video-calls-1o7#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>webdev</category>
      <category>webrtc</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>WebRTC, the Brain Behind Your Virtual Video Calls</title>
      <dc:creator>Blackwatch</dc:creator>
      <pubDate>Wed, 16 Jul 2025 14:38:39 +0000</pubDate>
      <link>https://dev.to/blackwatch021/webrtc-the-brain-behind-your-virtual-video-calls-1o7</link>
      <guid>https://dev.to/blackwatch021/webrtc-the-brain-behind-your-virtual-video-calls-1o7</guid>
      <description>&lt;p&gt;Ever wondered what goes behind apps like Google Meet or Zoom? How do they make it so easy for us to communicate through video, even when we're sitting on opposite sides of the planet?&lt;/p&gt;

&lt;p&gt;Yeah, I came across this while building an app for myself. That’s when I learned more about WebRTC—how it works, what goes on behind the scenes, what its architecture looks like, its drawbacks, and how to overcome them. In this article, I’ll give you a brief intro to WebRTC and its working principles. So stay tuned to dive deep into the world of video calling.&lt;/p&gt;

&lt;h2&gt;
  
  
  WebRTC—What Is This?
&lt;/h2&gt;

&lt;p&gt;It’s a protocol used to connect users directly so they can communicate, share files, stream video, and more.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;But aren’t there other protocols for that? What’s so special about this one?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Right, there are many protocols. But WebRTC shines because of &lt;strong&gt;its ease of use&lt;/strong&gt;, and the fact that you &lt;strong&gt;don’t need a dedicated server to monitor or relay the entire communication&lt;/strong&gt;. It’s based on the UDP protocol.&lt;/p&gt;

&lt;p&gt;Yes, you heard it right—WebRTC doesn’t need a third-party or cloud-based server for actual media transfer. It establishes a &lt;strong&gt;direct peer-to-peer connection&lt;/strong&gt; between users, which also makes it faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  So Why Don’t We Use This Everywhere?
&lt;/h2&gt;

&lt;p&gt;You might have the same question in your head. The reason is packet loss.&lt;/p&gt;

&lt;p&gt;WebRTC is based on &lt;strong&gt;UDP&lt;/strong&gt;, which is fast, but not reliable—it doesn’t guarantee that all data packets will reach the destination. That’s fine for things like Zoom meetings or online games, where a small data loss (a freeze or glitch) doesn’t affect much.&lt;/p&gt;

&lt;p&gt;But for &lt;strong&gt;messaging apps&lt;/strong&gt;, we can’t afford to lose even a single packet—missing words or characters can change the entire meaning of a message. So for these cases, we use &lt;strong&gt;TCP&lt;/strong&gt;, which ensures reliable and ordered delivery of data.&lt;/p&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use UDP/WebRTC for real-time media (video/audio).&lt;/li&gt;
&lt;li&gt;Use TCP when all data must be received correctly (text, files).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How It Works – Architecture
&lt;/h2&gt;

&lt;p&gt;Before diving in, let’s imagine a situation:&lt;br&gt;
You want to call your friend, family member, boss (to ask for leave 😁), or your wife (to plan a day out). To do that, you need their phone number. Only then can you call them.&lt;/p&gt;

&lt;p&gt;Similarly, in WebRTC, you first need to know the IP address of the person you want to connect with. But before that, let’s understand &lt;strong&gt;public and private IP addresses&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Public and Private IP Addresses
&lt;/h2&gt;

&lt;p&gt;Just like each SIM card has a unique number, every device needs a unique address on the internet to send and receive data.&lt;/p&gt;

&lt;p&gt;With the rapid growth in internet users, &lt;strong&gt;assigning a unique public IP to every device&lt;/strong&gt; isn't possible (due to IPv4 exhaustion). So instead, most devices are assigned &lt;strong&gt;private IP addresses&lt;/strong&gt; by routers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Public IP Address&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is what allows your device to access the internet.&lt;/li&gt;
&lt;li&gt;It’s unique globally and exposed to the outer world.&lt;/li&gt;
&lt;li&gt;Typically, only the router is assigned a public IP, and it communicates with the internet on behalf of all devices connected to it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;No two devices on the internet can have the same public IP.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Private IP Address&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Assigned to devices inside a local network (by the router).&lt;/li&gt;
&lt;li&gt;Can’t directly access the internet.&lt;/li&gt;
&lt;li&gt;Managed through a process called NAT (Network Address Translation).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So how do you surf the internet with a private IP?&lt;/p&gt;

&lt;p&gt;Here’s how:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When your device makes a request (e.g., opens a website), it goes to the router.&lt;/li&gt;
&lt;li&gt;The router forwards this request using its public IP.&lt;/li&gt;
&lt;li&gt;When the response comes back, it knows which device made the request and sends the data accordingly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feidwxtl0oztrog01jpeh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feidwxtl0oztrog01jpeh.png" alt="Private and Public IP addresses" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  TURN/ICE Servers
&lt;/h2&gt;

&lt;p&gt;Now that you know about private and public IPs, let’s talk about &lt;strong&gt;TURN and ICE servers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;After a device gets its private IP, it still doesn’t know its public IP, which is needed to establish a connection. That’s where these come in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;STUN/TURN servers&lt;/strong&gt; are simple services that see the public IP of incoming requests and send it back to the client.&lt;/li&gt;
&lt;li&gt;This way, the client becomes aware of its &lt;strong&gt;public IP address&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ICE (Interactive Connectivity Establishment) is a framework that uses STUN and TURN to find the best route between two peers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fps63i0h82xv2mhz4sg29.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fps63i0h82xv2mhz4sg29.png" alt="TURN server" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Signaling Server
&lt;/h2&gt;

&lt;p&gt;At this point, each user has the necessary information to establish a WebRTC connection—like codecs, IPs, ports, etc. This data is packaged in something called a &lt;strong&gt;Session Description Protocol&lt;/strong&gt; (SDP).&lt;/p&gt;

&lt;p&gt;But here's the catch:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You don’t have the other user’s SDP.&lt;/li&gt;
&lt;li&gt;They don’t have yours.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, we need a &lt;strong&gt;signaling server&lt;/strong&gt; to exchange this information.&lt;br&gt;
Don’t worry—it’s a &lt;strong&gt;simple server&lt;/strong&gt; that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Takes the SDP of User A and sends it to User B.&lt;/li&gt;
&lt;li&gt;Takes the SDP of User B and sends it to User A.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now both users have each other’s details and can establish a &lt;strong&gt;direct WebRTC connection&lt;/strong&gt;. After that, the signaling server isn’t needed anymore.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcfwpnpb3ij9pagmwsuf1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcfwpnpb3ij9pagmwsuf1.png" alt="Signalling server" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Drawbacks
&lt;/h2&gt;

&lt;p&gt;Since WebRTC is peer-to-peer, &lt;strong&gt;only two users&lt;/strong&gt; can connect at a time by default. You can’t host large video conferences using just this architecture.&lt;/p&gt;

&lt;p&gt;This is perfect for apps like &lt;strong&gt;Omegle&lt;/strong&gt;, where only two users need to connect. But for more users, we need other methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mesh Topology (Not Ideal)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft7mtnzixwm8xjoncg56o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft7mtnzixwm8xjoncg56o.png" alt="Mesh Topology" width="800" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In mesh, each user connects directly to every other user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: In a 4-user call, each user maintains 3 separate connections.&lt;/p&gt;

&lt;p&gt;This quickly becomes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bandwidth-heavy&lt;/li&gt;
&lt;li&gt;Hard to scale&lt;/li&gt;
&lt;li&gt;Difficult to keep all streams in sync&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s why mesh is rarely used in production apps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution – SFU (Selective Forwarding Unit) and Multipoint Control Units (MCUs)
&lt;/h2&gt;

&lt;p&gt;To solve the issue of scalability in WebRTC for group calls, we use &lt;strong&gt;SFU (Selective Forwarding Unit)&lt;/strong&gt; or &lt;strong&gt;MCU (Multipoint Control Unit)&lt;/strong&gt; as per the requirement. In both cases, we introduce a server into the architecture.&lt;/p&gt;

&lt;p&gt;In these setups, a &lt;strong&gt;server acts like a virtual client&lt;/strong&gt;, and all the users are connected to this server using a P2P configuration. This server handles the media streams from all users. In case of SFU, it simply forwards the streams to other users. In MCU, it combines all the streams into one and sends it back. This makes the data easier to manage, keeps it in sync, and helps in scaling the system to support many users at once. This is how big platforms like &lt;strong&gt;Google Meet, Zoom, Discord, Microsoft Teams, etc.&lt;/strong&gt;, manage large group calls.&lt;/p&gt;

&lt;h2&gt;
  
  
  SFU (Selective Forwarding Unit)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0r3xr36cafhykll0e88.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0r3xr36cafhykll0e88.webp" alt="SFU" width="720" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In SFU, each user sends their video/audio stream to the server, and the server’s job is just to **forward those streams **to the other users. It doesn’t mix or edit the media—it just acts like a smart postman.&lt;/p&gt;

&lt;p&gt;This way, each user only needs to upload their stream once, and the server takes care of distributing it to everyone else. Since the server isn’t doing any processing, this setup is &lt;strong&gt;lightweight and scalable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But there’s a catch. Each user still receives multiple streams—one from each participant—so the client device has to handle that load. Still, it’s much better than mesh topology, where everyone connects with everyone directly.&lt;/p&gt;

&lt;p&gt;That’s why SFU is the go-to choice for &lt;strong&gt;group video calls&lt;/strong&gt; in real-world apps. It's efficient, requires less server power, and performs well even with 10, 20, or more users.&lt;/p&gt;

&lt;h2&gt;
  
  
  MCU (Multipoint Control Unit)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl0xagybyk3s2qv8sdd3r.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl0xagybyk3s2qv8sdd3r.webp" alt="MCU" width="800" height="625"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this setup, things work a bit differently. All users send their streams to the server, just like in SFU. But here, the server does a lot more—it &lt;strong&gt;mixes all the streams into one combined video&lt;/strong&gt; (usually a grid of faces) and sends that &lt;strong&gt;single stream back&lt;/strong&gt; to every user.&lt;/p&gt;

&lt;p&gt;This keeps everything perfectly in sync and makes life easier for the client. Each device only needs to handle one incoming stream. But this also means the &lt;strong&gt;server is doing all the heavy lifting&lt;/strong&gt;—mixing, encoding, and streaming—which requires a lot more processing power and resources.&lt;/p&gt;

&lt;p&gt;MCU setups are great for situations like &lt;strong&gt;webinars or classrooms&lt;/strong&gt;, where it’s more important for everything to be in sync, and where users don’t interact much.&lt;/p&gt;

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

&lt;p&gt;With that, this article comes to an end. I hope you learned something new—because this was new to me too, and I thought, why not share my understanding with others?&lt;/p&gt;

&lt;p&gt;Thanks for reading, and I hope you enjoyed the article.&lt;/p&gt;

&lt;p&gt;Till we meet again—seeya, have a great day, keep learning, peace out.&lt;/p&gt;

&lt;p&gt;Signing off.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>webrtc</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
