{"id":21661,"date":"2025-06-15T15:20:50","date_gmt":"2025-06-15T15:20:50","guid":{"rendered":"https:\/\/gaviki.com\/blog\/?p=21661"},"modified":"2025-06-15T15:20:51","modified_gmt":"2025-06-15T15:20:51","slug":"what-are-the-sql-built-in-functions","status":"publish","type":"post","link":"https:\/\/gaviki.com\/blog\/what-are-the-sql-built-in-functions\/","title":{"rendered":"What are the SQL built-in functions"},"content":{"rendered":"\n<p>What are the SQL built-in functions? How do you use them in an SQL query? What is a subquery? When is a subquery executed?<\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\"><strong>The correct answer and explanation is:<\/strong><\/mark><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Correct Answer:<\/h3>\n\n\n\n<p><strong>1. SQL Built-in Functions:<\/strong><br>SQL provides several <strong>built-in functions<\/strong> used to perform operations on data. They are categorized as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Aggregate Functions:<\/strong> Work on multiple rows and return a single value.\n<ul class=\"wp-block-list\">\n<li><code>SUM()<\/code>, <code>AVG()<\/code>, <code>COUNT()<\/code>, <code>MAX()<\/code>, <code>MIN()<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Scalar Functions:<\/strong> Work on a single value and return a single value.\n<ul class=\"wp-block-list\">\n<li><code>UPPER()<\/code>, <code>LOWER()<\/code>, <code>LENGTH()<\/code>, <code>ROUND()<\/code>, <code>NOW()<\/code>, <code>GETDATE()<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>2. How to Use SQL Functions in a Query:<\/strong><\/p>\n\n\n\n<p>Example of <strong>aggregate functions<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT AVG(salary) AS average_salary FROM employees;\n<\/code><\/pre>\n\n\n\n<p>Example of <strong>scalar functions<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT UPPER(first_name) AS uppercase_name FROM employees;\n<\/code><\/pre>\n\n\n\n<p>You can also <strong>combine<\/strong> functions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT ROUND(AVG(salary), 2) AS avg_salary_rounded FROM employees;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>3. What is a Subquery?<\/strong><\/p>\n\n\n\n<p>A <strong>subquery<\/strong> (also called an inner query or nested query) is a query <strong>inside another query<\/strong>. It returns data that is used by the main query.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT name FROM employees\nWHERE salary &gt; (SELECT AVG(salary) FROM employees);\n<\/code><\/pre>\n\n\n\n<p>Here, the inner query calculates the average salary, and the outer query selects employees earning above that average.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>4. When is a Subquery Executed?<\/strong><\/p>\n\n\n\n<p>A subquery is executed <strong>first<\/strong> before the outer (main) query. Its result is passed to the main query for further processing. Depending on how it is used, subqueries can run:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Once for the entire outer query (scalar subquery)<\/li>\n\n\n\n<li>Once for each row processed by the outer query (correlated subquery)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u270d\ufe0f Summary (300 words):<\/h3>\n\n\n\n<p>SQL\u2019s built-in functions streamline data analysis and manipulation directly in queries. Aggregate functions like <code>SUM()<\/code>, <code>AVG()<\/code>, and <code>COUNT()<\/code> operate over multiple rows and are often used with <code>GROUP BY<\/code> to summarize data. Scalar functions, such as <code>UPPER()<\/code> or <code>ROUND()<\/code>, act on individual values and are useful for string formatting or mathematical rounding. These functions are embedded in <code>SELECT<\/code>, <code>WHERE<\/code>, or <code>HAVING<\/code> clauses to calculate or filter values dynamically.<\/p>\n\n\n\n<p>Subqueries add another layer of power and flexibility. By embedding one query inside another, subqueries help compare values or filter results based on computations like averages or maximums. For instance, selecting employees with salaries above the average involves a subquery to compute the average salary, followed by an outer query that uses this value for comparison.<\/p>\n\n\n\n<p>Execution timing matters: SQL first executes the subquery and then processes the main query using its result. In non-correlated subqueries, the subquery runs once. In correlated subqueries, it runs for each row of the outer query, which can impact performance.<\/p>\n\n\n\n<p>Used correctly, built-in functions and subqueries together allow SQL developers to write highly expressive and efficient data queries, reducing the need for application-side data processing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What are the SQL built-in functions? How do you use them in an SQL query? What is a subquery? When is a subquery executed? The correct answer and explanation is: \u2705 Correct Answer: 1. SQL Built-in Functions:SQL provides several built-in functions used to perform operations on data. They are categorized as: 2. How to Use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-21661","post","type-post","status-publish","format-standard","hentry","category-quiz-questions"],"_links":{"self":[{"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/posts\/21661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/comments?post=21661"}],"version-history":[{"count":1,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/posts\/21661\/revisions"}],"predecessor-version":[{"id":21663,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/posts\/21661\/revisions\/21663"}],"wp:attachment":[{"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/media?parent=21661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/categories?post=21661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/tags?post=21661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}