{"id":39035,"date":"2024-01-29T10:30:00","date_gmt":"2024-01-29T05:00:00","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=39035"},"modified":"2026-07-14T12:28:07","modified_gmt":"2026-07-14T06:58:07","slug":"sql-queries-with-examples","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/sql-queries-with-examples\/","title":{"rendered":"SQL Queries with Examples: Complete Guide from Basic to Advanced (2026)"},"content":{"rendered":"\n<p>SQL queries are commands used to retrieve, insert, update, and delete data in a relational database. If you can write a SELECT, a JOIN, and a GROUP BY confidently, you can handle most real-world database tasks, and most SQL interview rounds too.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>TL;DR Summary<\/strong><\/h2>\n\n\n\n<ul>\n<li>SELECT, WHERE, and ORDER BY handle basic data retrieval<\/li>\n\n\n\n<li>JOINs combine data across multiple tables<\/li>\n\n\n\n<li>GROUP BY and aggregate functions summarize data<\/li>\n\n\n\n<li>Subqueries and window functions solve advanced, interview-favorite problems<\/li>\n\n\n\n<li>SQL fits structured data; NoSQL fits flexible, high-volume data<\/li>\n<\/ul>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #ffffff; font-size: 18px; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 750px;\"><strong style=\"font-size: 22px; color: #ffffff;\">\ud83d\udca1 Did You Know?<\/strong><br \/><br \/>SQL was originally called SEQUEL (Structured English Query Language), built by IBM in the 1970s. Nearly 60% of developers worldwide still use it today, making it one of the most durable languages in tech.<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Some of the Most Common SQL Queries<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_32_44-PM-1200x675.webp\" alt=\"Some of the Most Common SQL Queries\" class=\"wp-image-121394\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_32_44-PM-1200x675.webp 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_32_44-PM-300x169.webp 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_32_44-PM-768x432.webp 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_32_44-PM-1536x864.webp 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_32_44-PM-150x84.webp 150w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_32_44-PM.webp 1672w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Query<\/th><th>Function<\/th><\/tr><\/thead><tbody><tr><td>SELECT * FROM table_name;<\/td><td>Retrieve all columns and rows from the specified table.<\/td><\/tr><tr><td>SELECT column1, column2 FROM table_name;<\/td><td>Retrieve specific columns from the specified table.<\/td><\/tr><tr><td>SELECT DISTINCT column FROM table_name;<\/td><td>Retrieve unique values from a specific column in the table.<\/td><\/tr><tr><td>WHERE condition;<\/td><td>Filter rows based on a specified condition in the WHERE clause.<\/td><\/tr><tr><td>ORDER BY column ASC\/DESC;<\/td><td>Sort the result set in ascending (ASC) or descending (DESC) order based on a specified column.<\/td><\/tr><tr><td>GROUP BY column;<\/td><td>Group rows based on the values in a specific column.<\/td><\/tr><tr><td>HAVING condition;<\/td><td>Filter groups based on a specified condition in the HAVING clause (used with GROUP BY).<\/td><\/tr><tr><td>INSERT INTO table_name (column1, column2) VALUES (value1, value2);<\/td><td>Insert new records into a table with specified column values.<\/td><\/tr><tr><td>UPDATE table_name SET column1 = value1 WHERE condition;<\/td><td>Update existing records in a table based on a specified condition.<\/td><\/tr><tr><td>DELETE FROM table_name WHERE condition;<\/td><td>Delete rows from a table based on a specified condition.<\/td><\/tr><tr><td>CREATE TABLE table_name (column1 datatype, column2 datatype, &#8230;);<\/td><td>Create a new table with specified columns and data types.<\/td><\/tr><tr><td>ALTER TABLE table_name ADD column_name datatype;<\/td><td>Add a new column to an existing table.<\/td><\/tr><tr><td>DROP TABLE table_name;<\/td><td>Delete an entire table along with its data.<\/td><\/tr><tr><td>SELECT COUNT(*) FROM table_name;<\/td><td>Count the number of rows in a table.<\/td><\/tr><tr><td>SELECT AVG(column) FROM table_name;<\/td><td>Calculate the average value of a numeric column in a table.<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">SQL Queries<\/figcaption><\/figure>\n\n\n\n<p><strong>Also Read | <a href=\"https:\/\/www.guvi.in\/blog\/how-to-learn-sql-using-squid-games\/\" target=\"_blank\" rel=\"noreferrer noopener\">How To Learn SQL Using Squid Games?<\/a><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>SELECT Statement<\/strong><\/h2>\n\n\n\n<p><strong>Difficulty: Beginner<\/strong><\/p>\n\n\n\n<p>SELECT retrieves data from a table. It&#8217;s the query you&#8217;ll write most often.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT first_name, last_name, salary\nFROM employees\nWHERE salary &gt; 70000;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>first_name<\/th><th>last_name<\/th><th>salary<\/th><\/tr><\/thead><tbody><tr><td>Rohan<\/td><td>Mehta<\/td><td>82000<\/td><\/tr><tr><td>Vikram<\/td><td>Singh<\/td><td>91000<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Output<\/strong><\/figcaption><\/figure>\n\n\n\n<p>Keep these in mind:<\/p>\n\n\n\n<ul>\n<li>Avoid <code>SELECT *<\/code> in production code \u2014 it&#8217;s slower and breaks silently when columns change<\/li>\n\n\n\n<li>Combine with WHERE, ORDER BY, and LIMIT to control exactly what comes back<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>JOIN Statements<\/strong><\/h2>\n\n\n\n<p><strong>Difficulty: Intermediate<\/strong><\/p>\n\n\n\n<p>JOINs combine rows from two or more tables using a shared column. Most real applications store data across multiple tables, so this is non-negotiable.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT s.first_name, c.course_name\nFROM students s\nJOIN courses c ON s.student_id = c.student_id;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>first_name<\/th><th>course_name<\/th><\/tr><\/thead><tbody><tr><td>Ananya<\/td><td>Data Science<\/td><\/tr><tr><td>Rohan<\/td><td>Web Development<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Output<\/strong><\/figcaption><\/figure>\n\n\n\n<p>INNER JOIN returns only matching rows. LEFT JOIN keeps every row from the first table even without a match. Mixing these up is one of the most common beginner errors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>GROUP BY Clause<\/strong><\/h2>\n\n\n\n<p><strong>Difficulty: Intermediate<\/strong><\/p>\n\n\n\n<p>GROUP BY summarizes rows into groups, usually paired with COUNT, SUM, or AVG.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT department_id, AVG(salary) AS avg_salary\nFROM employees\nGROUP BY department_id;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>department_id<\/th><th>avg_salary<\/th><\/tr><\/thead><tbody><tr><td>101<\/td><td>78500<\/td><\/tr><tr><td>102<\/td><td>85200<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Output<\/strong><\/figcaption><\/figure>\n\n\n\n<p>Use HAVING (not WHERE) if you need to filter after grouping \u2014 for example, showing only departments where the average salary exceeds \u20b980,000.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Subqueries<\/strong><\/h2>\n\n\n\n<p><strong>Difficulty: Advanced<\/strong><\/p>\n\n\n\n<p>A subquery is a query nested inside another query. It&#8217;s useful when a filter depends on a result you don&#8217;t know in advance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT first_name\nFROM employees\nWHERE salary &gt; (SELECT AVG(salary) FROM employees);<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>first_name<\/th><\/tr><\/thead><tbody><tr><td>Rohan<\/td><\/tr><tr><td>Vikram<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Output<\/strong><\/figcaption><\/figure>\n\n\n\n<p>CTEs (<code>WITH<\/code> clauses) do the same job with better readability for multi-step logic, and are the modern preference over deeply nested subqueries.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Window Functions<\/strong><\/h2>\n\n\n\n<p><strong>Difficulty: Advanced<\/strong><\/p>\n\n\n\n<p>Window functions calculate across related rows without collapsing them, using <code>OVER()<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT first_name, department_id, salary,\nRANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS dept_rank\nFROM employees;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>first_name<\/th><th>department_id<\/th><th>salary<\/th><th>dept_rank<\/th><\/tr><\/thead><tbody><tr><td>Vikram<\/td><td>101<\/td><td>91000<\/td><td>1<\/td><\/tr><tr><td>Rohan<\/td><td>101<\/td><td>82000<\/td><td>2<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Output<\/strong><\/figcaption><\/figure>\n\n\n\n<p>RANK() skips numbers on ties, ROW_NUMBER() never ties, and LAG()\/LEAD() pull values from neighboring rows \u2014 handy for period-over-period comparisons.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>SQL Interview Queries Asked at Amazon, Flipkart, TCS, Infosys<\/strong><\/h2>\n\n\n\n<p><strong>Difficulty: Intermediate to Advanced<\/strong><\/p>\n\n\n\n<p>These companies tend to test the same handful of query patterns. A few you should be able to write cold:<\/p>\n\n\n\n<p><strong>Find the second-highest salary (a favorite at TCS and Infosys):<\/strong><\/p>\n\n\n\n<p>sql<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT MAX(salary) AS second_highest\nFROM employees\nWHERE salary &lt; (SELECT MAX(salary) FROM employees);<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>second_highest<\/th><\/tr><\/thead><tbody><tr><td>82000<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Output<\/strong><\/figcaption><\/figure>\n\n\n\n<p><strong>Find duplicate records (common at Amazon and Flipkart data-heavy rounds):<\/strong><\/p>\n\n\n\n<p>sql<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT email, COUNT(*) \nFROM users\nGROUP BY email\nHAVING COUNT(*) &gt; 1;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>email<\/th><th>count<\/th><\/tr><\/thead><tbody><tr><td><a href=\"mailto:test@mail.com\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">test@mail.com<\/a><\/td><td>2<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Output<\/strong><\/figcaption><\/figure>\n\n\n\n<p><strong>Find employees with no matching department (LEFT JOIN + IS NULL, a classic Flipkart question):<\/strong><\/p>\n\n\n\n<p>sql<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT e.first_name\nFROM employees e\nLEFT JOIN departments d ON e.department_id = d.department_id\nWHERE d.department_id IS NULL;<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>first_name<\/th><\/tr><\/thead><tbody><tr><td>Priya<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Output<\/strong><\/figcaption><\/figure>\n\n\n\n<p>Interviewers are usually less interested in the exact syntax and more in whether you can explain your logic out loud. Practice narrating your thought process, not just typing the query.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>SQL vs NoSQL \u2014 When to Use Which?<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_35_15-PM-1200x675.webp\" alt=\"SQL vs NoSQL \u2014 When to Use Which?\" class=\"wp-image-121395\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_35_15-PM-1200x675.webp 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_35_15-PM-300x169.webp 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_35_15-PM-768x432.webp 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_35_15-PM-1536x864.webp 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_35_15-PM-150x84.webp 150w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_35_15-PM.webp 1672w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<p><strong>Difficulty: Beginner<\/strong><\/p>\n\n\n\n<p>This question comes up constantly once you move past query basics, especially in system design rounds.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Factor<\/th><th>SQL<\/th><th>NoSQL<\/th><\/tr><\/thead><tbody><tr><td>Data structure<\/td><td>Fixed schema, tables<\/td><td>Flexible, documents\/key-value<\/td><\/tr><tr><td>Relationships<\/td><td>Strong (joins)<\/td><td>Weak or none<\/td><\/tr><tr><td>Scaling<\/td><td>Vertical (mostly)<\/td><td>Horizontal, built for scale<\/td><\/tr><tr><td>Best for<\/td><td>Transactions, finance, ERP<\/td><td>Real-time apps, catalogs, logs<\/td><\/tr><tr><td>Examples<\/td><td>MySQL, PostgreSQL<\/td><td>MongoDB, Cassandra, Redis<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>SQL vs NoSQL \u2014 When to Use Which?<\/strong><\/figcaption><\/figure>\n\n\n\n<p>Simple rule of thumb: if your data has clear relationships and needs strong consistency, go SQL. If it&#8217;s high-volume, semi-structured, and needs to scale horizontally, <a href=\"https:\/\/www.guvi.in\/blog\/what-is-nosql\/\" target=\"_blank\" rel=\"noreferrer noopener\">NoSQL<\/a> fits better. Many real systems use both.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Mistakes to Avoid<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_36_49-PM-1200x675.webp\" alt=\"Common Mistakes to Avoid\" class=\"wp-image-121393\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_36_49-PM-1200x675.webp 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_36_49-PM-300x169.webp 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_36_49-PM-768x432.webp 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_36_49-PM-1536x864.webp 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_36_49-PM-150x84.webp 150w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/ChatGPT-Image-Jul-6-2026-09_36_49-PM.webp 1672w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<ul>\n<li>Confusing INNER JOIN with LEFT JOIN and losing rows silently<\/li>\n\n\n\n<li>Ignoring NULLs \u2014 use IS NULL or COALESCE instead of <code>= NULL<\/code><\/li>\n\n\n\n<li>Writing unindexed queries on large tables, which slows everything down<\/li>\n\n\n\n<li>Skipping practice on real datasets and only memorizing syntax<\/li>\n<\/ul>\n\n\n\n<p>Take your SQL skills to the next level with the <a href=\"https:\/\/www.guvi.in\/courses\/database-and-cloud-computing\/mysql\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=sql-queries-with-examples\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>MySQL Course<\/strong><\/a>. Gain hands-on experience in database management, query optimization, and real-world projects designed to build confidence and practical expertise. Master relational databases and strengthen your career prospects with industry-relevant skills.<\/p>\n\n\n\n<p><strong>Related Blog:<\/strong> <a href=\"https:\/\/www.placementpreparation.io\/blog\/sql-interview-questions-for-freshers\/?utm_source=guviblog&amp;utm_medium=hyperlink&amp;utm_campaign=sql-queries-with-examples\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/www.placementpreparation.io\/blog\/sql-interview-questions-for-freshers\/?utm_source=guviblog&amp;utm_medium=hyperlink&amp;utm_campaign=sql-queries-with-examples\" rel=\"noreferrer noopener\">SQL Interview Questions<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Mistakes Beginners Make in SQL<\/strong><\/h2>\n\n\n\n<p>Learning SQL becomes easier when you understand the mistakes that beginners often make. Avoiding these errors helps in building confidence and accuracy:<\/p>\n\n\n\n<ul>\n<li><strong>Using Wrong Joins: <\/strong>Beginners often confuse inner joins with left joins. This creates incomplete or incorrect results in the output.<br><em>The solution is to practice join queries with small datasets until the difference becomes clear.<\/em><\/li>\n\n\n\n<li><strong>Ignoring NULL Values: <\/strong>Many learners forget to handle NULL values, which leads to misleading query results. <em>The fix is to use functions like IS NULL or COALESCE to handle such cases.<\/em><\/li>\n\n\n\n<li><strong>Writing Unoptimized Queries: <\/strong>Long queries without indexing increase response time. Optimizing queries improves database performance. <em>The improvement comes from using indexes and breaking queries into smaller parts.<\/em><\/li>\n\n\n\n<li><strong>Not Practicing with Real Data: <\/strong>Working only on theory prevents learners from understanding how SQL performs on large datasets. Practical exposure builds better skills. <em>The best way to correct this is to practice with open-source datasets that simulate real projects.<\/em><\/li>\n<\/ul>\n\n\n\n<p class=\"has-text-align-center\"><strong><em>Ready to go from SQL beginner to pro?<br>HCL GUVI\u2019s <a href=\"https:\/\/www.guvi.in\/hub\/dbms-and-sql-tutorial?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=sql-queries-with-examples\" target=\"_blank\" rel=\"noreferrer noopener\">SQL Handbook<\/a><\/em><\/strong> <strong><em>guides you through practical examples, real-world projects, and hands-on exercises \u2014 all online and self-paced.<\/em><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Wrapping it Up<\/strong><\/h2>\n\n\n\n<p>These top SQL queries will give you an idea of how to work with databases efficiently. There are many SQL queries, but you can get started with these to kickstart your SQL journey. These SQL queries will help you to deal with databases, whether you&#8217;re a beginner or an experienced developer. You should get handy with these queries to enhance your SQL skills and become a proficient data professional.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1705735219708\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Q1. What is SQL?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p><strong>Ans<\/strong>. SQL (Structured Query Language) is a standard programming language designed for managing and manipulating relational databases. It enables users to perform various operations such as querying data, updating records, inserting new data, and more.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1705735236479\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Q2. Which databases use SQL?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p><strong>Ans<\/strong>. SQL is used by various relational database management systems (RDBMS) such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server, and Oracle Database, among others.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1705735253835\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Q3. How do I retrieve specific columns from a table?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p><strong>Ans<\/strong>. You can use this query to retrieve specific columns from a table: SELECT column1, column2 FROM table;<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1705735274139\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Q4. What is a subquery?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p><strong>Ans<\/strong>. A subquery is a query nested within another query. It can be used to retrieve data that will be used by the main query&#8217;s condition. <br \/>Example: SELECT column FROM table WHERE column IN (SELECT column FROM another_table);<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1783343408658\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Q5. Are subqueries slower than JOINs?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Not always, but JOINs are often more efficient for large datasets. Test both and check the execution plan when performance matters.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1783343427749\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Q6. What&#8217;s the fastest way to get better at SQL interviews?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Practice writing joins and subqueries by hand instead of just reading solutions \u2014 recall matters more than recognition.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>SQL queries are commands used to retrieve, insert, update, and delete data in a relational database. If you can write a SELECT, a JOIN, and a GROUP BY confidently, you can handle most real-world database tasks, and most SQL interview rounds too. TL;DR Summary \ud83d\udca1 Did You Know? SQL was originally called SEQUEL (Structured English [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":123294,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[325,16],"tags":[],"views":"147665","authorinfo":{"name":"Lukesh S","url":"https:\/\/www.guvi.in\/blog\/author\/lukesh\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2024\/01\/sql-queries-with-examples-2-300x116.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/39035"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=39035"}],"version-history":[{"count":87,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/39035\/revisions"}],"predecessor-version":[{"id":123295,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/39035\/revisions\/123295"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/123294"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=39035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=39035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=39035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}