{"id":4293,"date":"2025-01-25T10:46:49","date_gmt":"2025-01-25T10:46:49","guid":{"rendered":"https:\/\/www.kaashivinfotech.com\/blog\/?p=4293"},"modified":"2025-07-19T10:59:27","modified_gmt":"2025-07-19T10:59:27","slug":"20-common-sql-queries-with-examples","status":"publish","type":"post","link":"https:\/\/www.kaashivinfotech.com\/blog\/20-common-sql-queries-with-examples\/","title":{"rendered":"20 Most Common SQL Queries with Examples"},"content":{"rendered":"<h2 class=\"serp-title\">SQL Queries with Examples<\/h2>\n<p><a href=\"https:\/\/www.kaashivinfotech.com\/sql-server-course-in-chennai\/\">SQL (Structured Query Language)<\/a> is a standardized programming language used to manage and manipulate relational databases. It provides a way for users to interact with a database, including querying, updating, inserting, and deleting data. <a href=\"https:\/\/www.microsoft.com\/en-in\/sql-server\/sql-server-downloads\" target=\"_blank\" rel=\"noopener\">SQL<\/a> enables users to perform a variety of operations such as creating tables, modifying schema, and enforcing constraints to ensure data integrity.<\/p>\n<p>The language is based on a set of commands, such as <code class=\"\" data-line=\"\">SELECT<\/code>, <code class=\"\" data-line=\"\">INSERT<\/code>, <code class=\"\" data-line=\"\">UPDATE<\/code>, and <code class=\"\" data-line=\"\">DELETE<\/code>, which allow users to perform actions on data stored in tables.<a href=\"https:\/\/www.kaashivinfotech.com\/sql-internship\/\"> SQL<\/a> queries are the backbone of database management systems (DBMS), enabling users to retrieve information efficiently and perform complex data analysis. With SQL, you can filter, sort, and aggregate data, making it an essential tool for anyone working with relational databases.<\/p>\n<div class=\"block__bord\">\n<ul>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/sql-server-course-in-chennai\/\">SQL Server Course In Chennai<\/a><\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/sql-internship\/\">SQL Internship In Chennai<\/a><\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/courses\/\">Full Stack Developer Course In Chennai<\/a><\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/front-end-developer-course\/\">Front End Development Course In Chennai<\/a><\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/networking-training-in-chennai\/\">Networking Course In Chennai<\/a><\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/internship-in-chennai\/\">Internships In Chennai<\/a><\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/internship-for-cse-students\/\">Internship For CSE Students In Chennai<\/a><\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/internship-for-it-students\/\">Internship For IT Students In Chennai<\/a><\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/blog\/top-50-mini-project-ideas-for-college-students\/\">Top 50 Mini Project Ideas For College Students<\/a><\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/blog\/15-unique-web-development-project-ideas-for-beginners\/\">15 Unique Web Development Project Ideas For Beginners<\/a><\/li>\n<\/ul>\n<\/div>\n<p>SQL queries can be used in various ways to meet the specific needs of different applications. For example, a <code class=\"\" data-line=\"\">SELECT<\/code> query is used to fetch data from one or more tables, and it can be refined with additional clauses such as <code class=\"\" data-line=\"\">WHERE<\/code>, <code class=\"\" data-line=\"\">ORDER BY<\/code>, and <code class=\"\" data-line=\"\">GROUP BY<\/code> to manipulate the output. SQL queries are often used to join multiple tables, allowing users to combine data based on shared relationships. This relational approach to querying allows for more structured and efficient data retrieval. Furthermore,<\/p>\n<p>SQL includes powerful functions such as <code class=\"\" data-line=\"\">COUNT<\/code>, <code class=\"\" data-line=\"\">SUM<\/code>, and <code class=\"\" data-line=\"\">AVG<\/code>, which allow users to perform calculations on data. As databases grow in size and complexity, SQL remains an essential skill for developers, data analysts, and database administrators, enabling them to query, analyze, and manage large datasets effectively.<\/p>\n<h2>1. <strong>SELECT Statement<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">SELECT<\/code> statement is used to query a database and retrieve data from one or more tables.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; first_name, last_name &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query retrieves the <code class=\"\" data-line=\"\">first_name<\/code> and <code class=\"\" data-line=\"\">last_name<\/code> columns from the <code class=\"\" data-line=\"\">employees<\/code> table.<\/p>\n<hr \/>\n<h2>2. <strong>SELECT DISTINCT<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">DISTINCT<\/code> keyword is used to return only distinct (different) values in a column.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;DISTINCT&lt;\/span&gt; department &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query returns all unique department names from the <code class=\"\" data-line=\"\">employees<\/code> table.<\/p>\n<hr \/>\n<h2>3. <strong>WHERE Clause<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">WHERE<\/code> clause is used to filter records based on specified conditions.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;\/span&gt; salary &lt;span class=&quot;hljs-operator&quot;&gt;&gt;&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;50000&lt;\/span&gt;;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query selects all columns from the <code class=\"\" data-line=\"\">employees<\/code> table where the <code class=\"\" data-line=\"\">salary<\/code> is greater than 50,000.<\/p>\n<hr \/>\n<h2>4. <strong>AND, OR, NOT Operators<\/strong><\/h2>\n<p>These logical operators are used to filter records based on multiple conditions.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;\/span&gt; department &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&#039;HR&#039;&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;AND&lt;\/span&gt; salary &lt;span class=&quot;hljs-operator&quot;&gt;&gt;&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;50000&lt;\/span&gt;;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query returns all employees from the <code class=\"\" data-line=\"\">HR<\/code> department who have a salary greater than 50,000.<\/p>\n<hr \/>\n<h2>5. <strong>ORDER BY Clause<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">ORDER BY<\/code> clause is used to sort the result set by one or more columns.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees &lt;span class=&quot;hljs-keyword&quot;&gt;ORDER&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;\/span&gt; last_name &lt;span class=&quot;hljs-keyword&quot;&gt;ASC&lt;\/span&gt;;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query retrieves all employees and sorts them by the <code class=\"\" data-line=\"\">last_name<\/code> in ascending order.<\/p>\n<hr \/>\n<h2>6. <strong>INSERT INTO Statement<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">INSERT INTO<\/code> statement is used to insert new records into a table.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;INSERT&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;INTO&lt;\/span&gt; employees (first_name, last_name, department, salary)<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;VALUES&lt;\/span&gt; (&lt;span class=&quot;hljs-string&quot;&gt;&#039;John&#039;&lt;\/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#039;Doe&#039;&lt;\/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#039;Marketing&#039;&lt;\/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;60000&lt;\/span&gt;);<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query inserts a new employee record with the provided values into the <code class=\"\" data-line=\"\">employees<\/code> table.<\/p>\n<hr \/>\n<h2>7. <strong>UPDATE Statement<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">UPDATE<\/code> statement is used to modify existing records in a table.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;UPDATE&lt;\/span&gt; employees &lt;span class=&quot;hljs-keyword&quot;&gt;SET&lt;\/span&gt; salary &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;70000&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;\/span&gt; employee_id &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;101&lt;\/span&gt;;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query updates the salary of the employee with <code class=\"\" data-line=\"\">employee_id<\/code> 101 to 70,000.<\/p>\n<hr \/>\n<h2>8. <strong>DELETE Statement<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">DELETE<\/code> statement is used to remove one or more records from a table.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;DELETE&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;\/span&gt; employee_id &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;101&lt;\/span&gt;;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query deletes the record of the employee with <code class=\"\" data-line=\"\">employee_id<\/code> 101 from the <code class=\"\" data-line=\"\">employees<\/code> table.<\/p>\n<hr \/>\n<h2>9. <strong>JOIN Clause (INNER JOIN)<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">JOIN<\/code> clause is used to combine rows from two or more tables based on a related column.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; employees.first_name, departments.department_name<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;INNER&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;JOIN&lt;\/span&gt; departments &lt;span class=&quot;hljs-keyword&quot;&gt;ON&lt;\/span&gt; employees.department_id &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;\/span&gt; departments.department_id;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query retrieves the <code class=\"\" data-line=\"\">first_name<\/code> of employees and their corresponding <code class=\"\" data-line=\"\">department_name<\/code> by joining the <code class=\"\" data-line=\"\">employees<\/code> and <code class=\"\" data-line=\"\">departments<\/code> tables.<\/p>\n<hr \/>\n<h2>10. <strong>LEFT JOIN<\/strong><\/h2>\n<p>A <code class=\"\" data-line=\"\">LEFT JOIN<\/code> returns all records from the left table and the matching records from the right table.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; employees.first_name, departments.department_name<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;LEFT&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;JOIN&lt;\/span&gt; departments &lt;span class=&quot;hljs-keyword&quot;&gt;ON&lt;\/span&gt; employees.department_id &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;\/span&gt; departments.department_id;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query returns all employees, including those who may not belong to a department.<\/p>\n<hr \/>\n<h2>11. <strong>RIGHT JOIN<\/strong><\/h2>\n<p>A <code class=\"\" data-line=\"\">RIGHT JOIN<\/code> returns all records from the right table and the matching records from the left table.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; employees.first_name, departments.department_name<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;RIGHT&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;JOIN&lt;\/span&gt; departments &lt;span class=&quot;hljs-keyword&quot;&gt;ON&lt;\/span&gt; employees.department_id &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;\/span&gt; departments.department_id;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query returns all departments, even those without employees assigned to them.<\/p>\n<hr \/>\n<h2>12. <strong>FULL OUTER JOIN<\/strong><\/h2>\n<p>A <code class=\"\" data-line=\"\">FULL OUTER JOIN<\/code> returns all records when there is a match in either the left or right table.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; employees.first_name, departments.department_name<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;FULL&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;OUTER&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;JOIN&lt;\/span&gt; departments &lt;span class=&quot;hljs-keyword&quot;&gt;ON&lt;\/span&gt; employees.department_id &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;\/span&gt; departments.department_id;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query returns all employees and all departments, including those with no matching records in the other table.<\/p>\n<hr \/>\n<h2>13. <strong>GROUP BY Clause<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">GROUP BY<\/code> clause is used to group rows that have the same values in specified columns into summary rows.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; department, &lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;\/span&gt;(&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt;)<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;\/span&gt; department;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query returns the count of employees in each department.<\/p>\n<hr \/>\n<h2>14. <strong>HAVING Clause<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">HAVING<\/code> clause is used to filter records after the <code class=\"\" data-line=\"\">GROUP BY<\/code> clause has been applied.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; department, &lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;\/span&gt;(&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt;)<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;\/span&gt; department<br \/>\n&lt;span class=&quot;hljs-keyword&quot;&gt;HAVING&lt;\/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;\/span&gt;(&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt;) &lt;span class=&quot;hljs-operator&quot;&gt;&gt;&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;5&lt;\/span&gt;;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query retrieves departments with more than five employees.<\/p>\n<hr \/>\n<h2>15. <strong>LIMIT Clause<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">LIMIT<\/code> clause is used to specify the number of records to return.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees LIMIT &lt;span class=&quot;hljs-number&quot;&gt;10&lt;\/span&gt;;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query returns only the first 10 rows from the <code class=\"\" data-line=\"\">employees<\/code> table.<\/p>\n<hr \/>\n<h2>16. <strong>BETWEEN Operator<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">BETWEEN<\/code> operator is used to filter records within a range of values.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;\/span&gt; salary &lt;span class=&quot;hljs-keyword&quot;&gt;BETWEEN&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;40000&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;AND&lt;\/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80000&lt;\/span&gt;;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query selects employees with salaries between 40,000 and 80,000.<\/p>\n<hr \/>\n<h2>17. <strong>IN Operator<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">IN<\/code> operator is used to filter records based on a list of values.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;\/span&gt; department &lt;span class=&quot;hljs-keyword&quot;&gt;IN&lt;\/span&gt; (&lt;span class=&quot;hljs-string&quot;&gt;&#039;HR&#039;&lt;\/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&#039;Sales&#039;&lt;\/span&gt;);<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query retrieves all employees from either the HR or Sales departments.<\/p>\n<hr \/>\n<h2>18. <strong>LIKE Operator<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">LIKE<\/code> operator is used to search for a specified pattern in a column.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; &lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;\/span&gt; first_name &lt;span class=&quot;hljs-keyword&quot;&gt;LIKE&lt;\/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&#039;J%&#039;&lt;\/span&gt;;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query returns employees whose first names start with the letter &#8220;J&#8221;.<\/p>\n<hr \/>\n<h2>19. <strong>COUNT Function<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">COUNT<\/code> function is used to return the number of rows that match a specified condition.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;COUNT&lt;\/span&gt;(&lt;span class=&quot;hljs-operator&quot;&gt;*&lt;\/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees &lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;\/span&gt; department &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;\/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&#039;Marketing&#039;&lt;\/span&gt;;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query returns the number of employees in the <code class=\"\" data-line=\"\">Marketing<\/code> department.<\/p>\n<hr \/>\n<h2>20. <strong>MAX and MIN Functions<\/strong><\/h2>\n<p>The <code class=\"\" data-line=\"\">MAX<\/code> and <code class=\"\" data-line=\"\">MIN<\/code> functions are used to return the highest and lowest values in a column, respectively.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"\" data-line=\"\">&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;\/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;MAX&lt;\/span&gt;(salary), &lt;span class=&quot;hljs-built_in&quot;&gt;MIN&lt;\/span&gt;(salary) &lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;\/span&gt; employees;<br \/>\n<\/code><\/div>\n<\/div>\n<p>This query returns the highest and lowest salaries from the <code class=\"\" data-line=\"\">employees<\/code> table.<\/p>\n<hr \/>\n<p>In conclusion, SQL queries are the foundation of managing and manipulating data within relational databases. They provide a powerful way to retrieve, update, insert, and delete data, making it an indispensable tool for data management and analysis. Whether you&#8217;re working with large datasets, complex data relationships, or performing routine database maintenance, SQL ensures that you can interact with your data efficiently and effectively. Mastering SQL not only helps in understanding the core functionality of relational databases but also opens up opportunities for more advanced data analysis and optimization techniques.<\/p>\n<p>If you&#8217;re looking to learn more about SQL or need expert assistance in integrating SQL solutions into your projects, feel free to contact us. Visit our website, <a href=\"https:\/\/www.kaashivinfotech.com\/\"><strong>Kaashiv Infotech<\/strong><\/a>, for more information and support tailored to your needs. Our team is here to help you navigate the world of databases and SQL with professional guidance and expertise!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL Queries with Examples SQL (Structured Query Language) is a standardized programming language used to manage and manipulate relational databases. It provides a way for users to interact with a database, including querying, updating, inserting, and deleting data. SQL enables users to perform a variety of operations such as creating tables, modifying schema, and enforcing [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":4305,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3204],"tags":[2946,2947,2949,2953,2951,2948,2950,2952],"class_list":["post-4293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-20-most-common-sql-queries-with-examples-interview-questions","tag-all-sql-queries-with-examples-pdf","tag-basic-sql-queries-with-examples","tag-important-queries-in-sql-for-interview","tag-sql-query-examples-create-table","tag-sql-query-examples-with-answers","tag-top-100-sql-query-interview-questions-pdf","tag-tricky-sql-queries-for-interview"],"_links":{"self":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/4293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=4293"}],"version-history":[{"count":0,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/4293\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/media\/4305"}],"wp:attachment":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=4293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=4293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=4293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}