Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
SQL | String functions
Next article icon

SQL | String functions

Last Updated : 24 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

SQL String Functions are powerful tools that allow us to manipulate, format, and extract specific parts of text data in our database. These functions are essential for tasks like cleaning up data, comparing strings, and combining text fields. Whether we're working with names, addresses, or any form of textual data, mastering SQL string functions is crucial for efficient data handling and analysis.

Common SQL String Functions

String functions are used to perform an operation on input string and return an output string. Below are some of the most commonly used SQL string functions:

1. CONCAT(): Concatenate Strings

The CONCAT() function is used to concatenate (combine) two or more strings into one string. It is useful when we want to merge fields like first and last names into a full name.

Query:

SELECT CONCAT('John', ' ', 'Doe') AS FullName;

Output:

John Doe

2. CHAR_LENGTH() / CHARACTER_LENGTH(): Find String Length

The CHAR_LENGTH() or LENGTH() function returns the length of a string in characters. It’s essential for validating or manipulating text data, especially when you need to know how many characters a string contains.

Query:

SELECT CHAR_LENGTH('Hello') AS StringLength;

Output:

5

3. UPPER() and LOWER(): Convert Text Case

These functions convert the text to uppercase or lowercase, respectively. They are useful for normalizing the case of text in a database.

Query:

SELECT UPPER('hello') AS UpperCase;
SELECT LOWER('HELLO') AS LowerCase;

Output:

HELLO
hello

4. LENGTH(): Length of String in Bytes

LENGTH() returns the length of a string in bytes. This can be useful for working with multi-byte character sets.

Query:

SELECT LENGTH('Hello') AS LengthInBytes;

Output:

5

5. REPLACE(): Replace Substring in String

The REPLACE() function replaces occurrences of a substring within a string with another substring. This is useful for cleaning up data, such as replacing invalid characters or formatting errors.

Query:

SELECT REPLACE('Hello World', 'World', 'SQL') AS UpdatedString;

Output:

Hello SQL

6. SUBSTRING() / SUBSTR(): Extract Part of a String

The SUBSTRING() (or SUBSTR()) function is used to extract a substring from a string, starting from a specified position. It is especially useful when we need to extract a specific part of a string, like extracting the domain from an email address.

Query:

SELECT SUBSTRING('Hello World', 1, 5) AS SubStringExample;

Output:

Hello

7. LEFT() and RIGHT(): Extract Substring from Left or Right

The LEFT() and RIGHT() functions allow you to extract a specified number of characters from the left or right side of a string, respectively. It is used for truncating strings for display.

Query:

SELECT LEFT('Hello World', 5) AS LeftString;
SELECT RIGHT('Hello World', 5) AS RightString;

Output:

Hello    
World

8. INSTR(): Find Position of Substring

The INSTR() function is used to find the position of the first occurrence of a substring within a string. It returns the position (1-based index) of the substring. If the substring is not found, it returns 0. This function is particularly useful for locating specific characters or substrings in text data.

Query:

SELECT INSTR('Hello World', 'World') AS SubstringPosition;

Output:

7

9. TRIM(): Remove Leading and Trailing Spaces

The TRIM() function removes leading and trailing spaces (or other specified characters) from a string. By default, it trims spaces but can also remove specific characters using TRIM(character FROM string). This is helpful for cleaning text data, such as user inputs or database records.

Query:

SELECT TRIM(' ' FROM '  Hello World  ') AS TrimmedString;

Output:

Hello World

10. REVERSE(): Reverse the String

The REVERSE() function reverses the characters in a string. It’s useful in situations where we need to process data backward, such as for password validation or certain pattern matching.

Query:

SELECT REVERSE('Hello') AS ReversedString;

Output:

olleH

Other String Functions

In SQL, beyond the basic string functions, there are several advanced string functions that can help you manipulate and process string data more effectively. These functions provide powerful tools for working with text, whether you're cleaning data, formatting outputs, or comparing strings. These are the some additional SQL Functions.

11. ASCII():Get the ASCII Value of a Character

The ASCII() function returns the ASCII value of a single character. This is helpful when we need to find the numeric code corresponding to a character, often used in encoding and decoding text.

Syntax:

SELECT ascii('t');

Output:

 116

12. CONCAT_WS(): Concatenate Strings with a Separator

CONCAT_WS() stands for "Concatenate With Separator." It allows us to join multiple strings with a specific separator between them. This is ideal when we need to merge columns like first name and last name with a custom separator.

Syntax:

SELECT CONCAT_WS('_', 'geeks', 'for', 'geeks');

Output:

geeks_for_geeks

13. FIND_IN_SET(): Find Position of a Value in a Comma-Separated List

The FIND_IN_SET() function returns the position of a value within a comma-separated list. This is especially useful for finding out where an element exists in a string of values (e.g., tags, categories).

Syntax:

SELECT FIND_IN_SET('b', 'a, b, c, d, e, f');

Output:

 2

14. FORMAT(): Format Numbers for Readable Output

The FORMAT() function is used to format a number as a string in a specific way, often with commas for thousands or with a specific number of decimal places. It's handy when you need to display numbers in a user-friendly format.

Syntax:

SELECT FORMAT(0.981 * 100, 'N2') + '%' AS PercentageOutput;

Output:

‘98.10%’

15. INSTR(): Find the Position of a Substring

The INSTR() function returns the position of the first occurrence of a substring within a string. If the substring is not found, it returns 0. It's useful for finding where specific text appears in a larger string.

Syntax:

SELECT INSTR('geeks for geeks', 'e');

Output:

2 

16. LCASE(): Convert String to Lowercase

The LCASE() function converts all characters in a string to lowercase. It helps standardize text data, especially when comparing strings in a case-insensitive way.

Syntax:

SELECT LCASE ("GeeksFor Geeks To Learn");

Output:

geeksforgeeks to learn

17. LOCATE(): Find the nth Position of a Substring

LOCATE() allows you to find the nth occurrence of a substring in a string. This is especially useful when you need to locate a specific substring based on its position.

Syntax:

SELECT LOCATE('for', 'geeksforgeeks', 1);

Output:

 6

18. LPAD(): Pad the Left Side of a String

LPAD() is used to pad a string to a certain length by adding characters to the left side of the original string. It's useful when you need to format data to a fixed length.

Syntax:

SELECT LPAD('geeks', 8, '0');

Output:

000geeks

19. MID(): Extract a Substring from the Middle

MID() extracts a substring starting from a given position in a string and for a specified length. It's useful when you want to extract a specific portion of a string.

Syntax:

SELECT Mid ("geeksforgeeks", 6, 2);

Output:

for

20. POSITION(): Find the Position of a Character in a String

The POSITION() function finds the position of the first occurrence of a specified character in a string.

Syntax:

SELECT POSITION('e' IN 'geeksforgeeks');

Output:

2

21. REPEAT(): Repeat a String Multiple Times

The REPEAT() function repeats a string a specified number of times. It's useful when you need to duplicate a string or pattern for certain operations.

Syntax:

SELECT REPEAT('geeks', 2);

Output:

geeksgeeks

22. REPLACE(): Replace a Substring in a String

REPLACE() is used to replace all occurrences of a substring with another substring. It's useful for replacing or cleaning up certain text in your data.

Syntax:

REPLACE('123geeks123', '123');

Output:

geeks

23. RPAD(): Pad the Right Side of a String

RPAD() pads the right side of a string with specified characters to a fixed length. This is often used to format text or numbers to a desired size.

Syntax:

RPAD('geeks', 8, '0');

Output:

 ‘geeks000’

24. RTRIM(): Remove Trailing Characters

RTRIM() removes trailing characters from the right side of a string. By default, it removes spaces, but you can specify other characters as well.

Syntax:

RTRIM('geeksxyxzyyy', 'xyz');

Output:

 ‘geeks’

25. SPACE(): Generate a String of Spaces

The SPACE() function generates a string consisting of a specified number of spaces. This is useful when you need to format output or create padding in your queries.

Syntax:

SELECT SPACE(7);

Output:

 ‘       ‘

26. STRCMP(): Compare Two Strings

STRCMP() compares two strings and returns an integer value based on their lexicographical comparison. This is useful for sorting or checking equality between two strings. STRCMP(string1, string2) returns:

  • 0 if both strings are equal.
  • A negative value if string1 is less than string2.
  • A positive value if string1 is greater than string2.

Syntax

SELECT STRCMP('google.com', 'geeksforgeeks.com');

Output:

 1

Summary of String Functions

Below is a table summarizing these functions, their purposes, and examples.

FunctionDescriptionExample QueryOutput
ASCII()Find ASCII value of a character.SELECT ASCII('A');65
CONCAT_WS()Concatenate with a delimiter.SELECT CONCAT_WS('_', 'A', 'B');A_B
FIND_IN_SET()Find position in a set.SELECT FIND_IN_SET('b', 'a,b,c');2
LOCATE()Find nth occurrence.SELECT LOCATE('e', 'geeksforgeeks', 1);2
LPAD()Pad string from the left.SELECT LPAD('geeks', 8, '0');000geeks
POSITION()Find character position.SELECT POSITION('e' IN 'geeks');2
REPEAT()Repeat a string.SELECT REPEAT('SQL', 3);SQLSQLSQL
RTRIM()Remove trailing characters.SELECT RTRIM('SQLXYZ', 'XYZ');SQL

Conclusion

SQL String Functions are powerful tools for manipulating and analyzing string data in databases. Whether we need to concatenate, extract, compare, or modify strings, these functions provide the flexibility to handle a wide variety of string-related tasks. Understanding and applying these functions can make our SQL queries more efficient and help us manipulate data exactly as we need.


Next Article
SQL | String functions

S

Sakshi98
Improve
Article Tags :
  • Misc
  • SQL
  • Databases
  • SQL-Functions
Practice Tags :
  • Misc

Similar Reads

    SQL Tutorial
    Structured Query Language (SQL) is the standard language used to interact with relational databases. Whether you want to create, delete, update or read data, SQL provides the structure and commands to perform these operations. SQL is widely supported across various database systems like MySQL, Oracl
    8 min read

    SQL Basics

    What is Database?
    A database is an organized collection of data stored electronically. It allows users and applications to easily access, update, and manipulate information. This data contains text, numbers, images, videos and more. Databases are managed using specialized software known as a Database Management Syste
    13 min read
    Types of Databases
    Databases are essential for storing and managing data in today’s digital world. They serve as the backbone of various applications, from simple personal projects to complex enterprise systems. Understanding the different types of databases is crucial for choosing the right one based on specific requ
    11 min read
    Introduction of DBMS (Database Management System)
    A Database Management System (DBMS) is a software solution designed to efficiently manage, organize, and retrieve data in a structured manner. It serves as a critical component in modern computing, enabling organizations to store, manipulate, and secure their data effectively. From small application
    8 min read
    Non-Relational Databases and Their Types
    In the area of database management, the data is arranged in two ways which are Relational Databases (SQL) and Non-Relational Databases (NoSQL). While relational databases organize data into structured tables, non-relational databases use various flexible data models like key-value pairs, documents,
    7 min read
    What is SQL?
    SQL was invented in the 1970s by IBM and was first commercially distributed by Oracle. The original name was SEQUEL (Structured English Query Language), later shortened to SQL. It is a standardized programming language used to manage, manipulate and interact with relational databases. It allow users
    9 min read
    SQL Data Types
    SQL Data Types are very important in relational databases. It ensures that data is stored efficiently and accurately. Data types define the type of value a column can hold, such as numbers, text, or dates. Understanding SQL Data Types is critical for database administrators, developers, and data ana
    5 min read
    SQL Operators
    SQL operators are important in DBMS as they allow us to manipulate and retrieve data efficiently. Operators in SQL perform arithmetic, logical, comparison, bitwise, and other operations to work with database values. Understanding SQL operators is crucial for performing complex data manipulations, ca
    5 min read
    SQL Commands | DDL, DQL, DML, DCL and TCL Commands
    SQL commands are crucial for managing databases effectively. These commands are divided into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Data Query Language (DQL), and Transaction Control Language (TCL). In this article, we will e
    7 min read

    Create Database in SQL

    SQL CREATE DATABASE
    Creating a database is one of the fundamental tasks in SQL. It is the first step in designing a relational data system. Understanding how to use this command effectively is crucial for developers, database administrators and anyone working with relational databases.What is the CREATE DATABASE Comman
    5 min read
    SQL DROP DATABASE
    The SQL DROP DATABASE statement is an important command used to permanently delete a database from the Database Management System (DBMS). When executed, this command removes the database and all its associated objects, including tables, views, stored procedures, and other entities.In this article, w
    4 min read
    SQL Query to Rename Database
    Renaming a database in SQL is an essential task that database administrators and developers frequently perform. Whether you’re reorganizing your data, correcting naming conventions, or simply updating your project structure, knowing how to rename a database properly is critical. In this article, we'
    4 min read
    SQL Select Database
    The USE DATABASE statement is a command in certain SQL-based database management systems that allows users to select and set a specific database as the default for the current session. By selecting a database, subsequent queries are executed within the context of that database, making it easier to i
    4 min read

    Tables in SQL

    SQL CREATE TABLE
    In SQL, creating a table is one of the most essential tasks for structuring your database. The CREATE TABLE statement defines the structure of the database table, specifying column names, data types, and constraints such as PRIMARY KEY, NOT NULL, and CHECK. Mastering this statement is fundamental to
    5 min read
    SQL DROP TABLE
    The DROP TABLE command in SQL is a powerful and essential tool used to permanently delete a table from a database, along with all of its data, structure, and associated constraints such as indexes, triggers, and permissions. When executed, this command removes the table and all its contents, making
    4 min read
    SQL DELETE Statement
    The SQL DELETE statement is an essential command in SQL used to remove one or more rows from a database table. Unlike the DROP statement, which removes the entire table, the DELETE statement removes data (rows) from the table retaining only the table structure, constraints, and schema. Whether you n
    4 min read
    ALTER (RENAME) in SQL
    In SQL, making structural changes to a database is often necessary. Whether it's renaming a table or a column, adding new columns, or modifying data types, the SQL ALTER TABLE command plays a critical role. This command provides flexibility to manage and adjust database schemas without affecting the
    5 min read
    DROP and TRUNCATE in SQL
    The DROP and TRUNCATE commands in SQL are used to remove data from a table, but they work differently. Understanding the difference between these two commands is important for proper database management, especially when dealing with large amounts of data. SQL DROP CommandThe SQL DROP command is used
    5 min read
    SQL Query to Create a Backup Table
    Relational databases play an important role in managing data, especially during complex operations like updates and deletions. To maintain data integrity, it is essential to back up tables before making changes. SQL backup tables ensure the safety of the original dataset, allow for data recovery, an
    5 min read
    What is Temporary Table in SQL?
    A temporary table in SQL is an important tool for maintaining intermediate results during query execution. They help store temporary data without affecting the underlying permanent tables. In this article, we’ll explore temporary tables in SQL, their types (local vs. global), and how to use them eff
    3 min read
    SQL ALTER TABLE
    The SQL ALTER TABLE statement is a powerful tool that allows you to modify the structure of an existing table in a database. Whether you are adding new columns, modifying existing ones, deleting columns or renaming them, the ALTER TABLE statement enables you to make changes without losing the data s
    5 min read

    SQL Queries

    SQL SELECT Query
    The SQL SELECT query is one of the most frequently used commands to retrieve data from a database. It allows users to access and extract specific records based on defined conditions, making it an essential tool for data management and analysis. In this article, we will learn about SQL SELECT stateme
    4 min read
    SQL TOP, LIMIT, FETCH FIRST Clause
    SQL TOP, LIMIT, and FETCH FIRST clauses are used to retrieve a specific number of records from a table. These clauses are especially useful in large datasets with thousands of records.Each of these SQL clauses performs a similar operation of limiting the results returned by a query, but different da
    8 min read
    SQL SELECT FIRST
    The SELECT FIRST clause is used in some SQL databases (primarily MS Access) to retrieve the first record from a table based on the order in which data is stored or queried. It is commonly used when you need to access just one entry, such as the first row based on the natural order or after sorting b
    3 min read
    SQL - SELECT LAST
    SELECT LAST is a concept or function often used to describe retrieving the last record or last row from a table in SQL. Although MS Access supports a LAST() function to directly fetch the last value from a column, this function is not universally supported across all SQL-based databases. Instead, in
    5 min read
    SQL - SELECT RANDOM
    In SQL, the RANDOM() function is used to fetch random rows from a table. It is an extremely useful function in various applications, such as selecting random users, retrieving random questions from a pool, or even for random sampling in data analysis. In this article, we will explore how to use RAND
    3 min read
    SQL SELECT IN Statement
    The IN operator in SQL is used to compare a column's value against a set of values. It returns TRUE if the column's value matches any of the values in the specified list, and FALSE if there is no match.In this article, we will learn how IN operator works and provide practical examples to help you be
    3 min read
    SQL - SELECT DATE
    SQL (Structured Query Language) can work with datetime data types. SELECT DATE is an important concept when retrieving records that filter data based on date. Whether you work with employee records, transaction records, or product sales, modifying and retrieving date data is often important for your
    3 min read
    SQL Query to Insert Multiple Rows
    In SQL, the INSERT statement is used to add new records to a database table. When you need to insert multiple rows in a single query, the INSERT statement becomes efficient.In this article, We will learn different methods such as using basic INSERT statements, utilizing INSERT INTO ... SELECT for bu
    4 min read
    SQL INSERT INTO Statement
    The SQL INSERT INTO statement is one of the most essential commands for adding new data into a database table. Whether you are working with customer records, product details or user information, understanding and mastering this command is important for effective database management. How SQL INSERT I
    6 min read
    SQL UPDATE Statement
    In SQL, the UPDATE statement is used to modify existing records in a table. Whether you are updating a single record or multiple records at once, SQL provides the necessary functionality to make these changes. Whether you are working with a small dataset or handling large-scale databases, the UPDATE
    6 min read
    SQL DELETE Statement
    The SQL DELETE statement is an essential command in SQL used to remove one or more rows from a database table. Unlike the DROP statement, which removes the entire table, the DELETE statement removes data (rows) from the table retaining only the table structure, constraints, and schema. Whether you n
    4 min read
    SQL Query to Delete Duplicate Rows
    Duplicate rows in a database can cause inaccurate results, waste storage space, and slow down queries. Cleaning duplicate records from our database is an essential maintenance task for ensuring data accuracy and performance. Duplicate rows in a SQL table can lead to data inconsistencies and performa
    6 min read

    SQL Clauses

    SQL | WHERE Clause
    The SQL WHERE clause allows filtering of records in queries. Whether you are retrieving data, updating records, or deleting entries from a database, the WHERE clause plays an important role in defining which rows will be affected by the query. Without WHERE clause, SQL queries would return all rows
    4 min read
    SQL | WITH Clause
    SQL queries can sometimes be complex, especially when you need to deal with multiple nested subqueries, aggregations, and joins. This is where the SQL WITH clause also known as Common Table Expressions (CTEs) comes in to make life easier. The WITH Clause is a powerful tool that simplifies complex SQ
    6 min read
    SQL HAVING Clause with Examples
    The HAVING clause in SQL is used to filter query results based on aggregate functions. Unlike the WHERE clause, which filters individual rows before grouping, the HAVING clause filters groups of data after aggregation. It is commonly used with functions like SUM(), AVG(), COUNT(), MAX(), and MIN().
    4 min read
    SQL ORDER BY
    The ORDER BY clause in SQL is a powerful feature used to sort query results in either ascending or descending order based on one or more columns. Whether you are presenting data to users or analyzing large datasets, sorting the results in a structured way is essential. In this article, we will explo
    5 min read
    SQL | GROUP BY
    The SQL GROUP BY clause is a powerful tool used to organize data into groups based on shared values in one or more columns. It is most often used with aggregate functions like SUM, COUNT, AVG, MIN and MAX to perform summary operations on each group, helping us extract meaningful analysis from large
    5 min read
    SQL LIMIT Clause
    The LIMIT clause in SQL is used to control the number of rows returned in a query result. It is particularly useful when working with large datasets, allowing us to retrieve only the required number of rows for analysis or display. Whether we're looking to paginate results, find top records, or just
    5 min read

    SQL Operators

    SQL AND and OR Operators
    The SQL AND and OR operators are used to filter data based on multiple conditions. These logical operators allow users to retrieve precise results from a database by combining various conditions in SELECT, INSERT, UPDATE, and DELETE statements.In this article, we'll learn the AND and OR operators, d
    3 min read
    SQL AND and OR Operators
    The SQL AND and OR operators are used to filter data based on multiple conditions. These logical operators allow users to retrieve precise results from a database by combining various conditions in SELECT, INSERT, UPDATE, and DELETE statements.In this article, we'll learn the AND and OR operators, d
    3 min read
    SQL LIKE Operator
    The SQL LIKE operator is used for performing pattern-based searches in a database. It is used in combination with the WHERE clause to filter records based on specified patterns, making it essential for any database-driven application that requires flexible search functionality.In this article, we wi
    5 min read
    SQL IN Operator
    The SQL IN operator filters data based on a list of specific values. In general, we can only use one condition in the Where clause, but the IN operator allows us to specify multiple values. In this article, we will learn about the IN operator in SQL by understanding its syntax and examples.IN Operat
    4 min read
    SQL NOT Operator
    The SQL NOT Operator is a logical operator used to negate or reverse the result of a condition in SQL queries. It is commonly used with the WHERE clause to filter records that do not meet a specified condition, helping you exclude certain values from your results.In this article, we will learn every
    3 min read
    SQL NOT EQUAL Operator
    The SQL NOT EQUAL operator is a comparison operator used to check if two expressions are not equal to each other. It helps filter out records that match certain conditions, making it a valuable tool in SQL queries.In this article, We will explore the SQL NOT EQUAL operator, including its syntax, use
    4 min read
    SQL IS NULL
    The SQL IS NULL operator is a logical operator used to identify and filter out rows with NULL values in a column. A NULL value represents missing or undefined data in a database. It is different from a zero value or blank space, and it indicates that the value is unknown.In this article, we will lea
    4 min read
    SQL UNION Operator
    The SQL UNION operator is used to combine the result sets of two or more SELECT queries into a single result set. It is a powerful tool in SQL that helps aggregate data from multiple tables, especially when the tables have similar structures.In this guide, we'll explore the SQL UNION operator, how i
    4 min read
    SQL UNION ALL
    UNION ALL Operator is used to combine the results of two or more SELECT statements into a single result set. Unlike the UNION operator, which eliminates duplicate records and UNION ALL includes all duplicates. This makes UNION ALL it faster and more efficient when we don't need to remove duplicates.
    4 min read
    SQL | Except Clause
    The SQL EXCEPT operator is used to return the rows from the first SELECT statement that are not present in the second SELECT statement. This operator is conceptually similar to the subtract operator in relational algebra. It is particularly useful for excluding specific data from your result set.In
    4 min read
    SQL BETWEEN Operator
    The BETWEEN operator in SQL is used to filter records within a specific range. Whether applied to numeric, text, or date columns it simplifies the process of retrieving data that falls within a particular boundary. In this article, we will explore the SQL BETWEEN operator with examples.SQL BETWEEN O
    3 min read
    SQL | ALL and ANY
    In SQL, the ALL and ANY operators are logical operators used to compare a value with a set of values returned by a subquery. These operators provide powerful ways to filter results based on a range of conditions. In this article, we will explore ALL and ANY in SQL, their differences, and how to use
    4 min read
    SQL | ALL and ANY
    In SQL, the ALL and ANY operators are logical operators used to compare a value with a set of values returned by a subquery. These operators provide powerful ways to filter results based on a range of conditions. In this article, we will explore ALL and ANY in SQL, their differences, and how to use
    4 min read
    SQL | INTERSECT Clause
    In SQL, the INTERSECT clause is used to retrieve the common records between two SELECT queries. It returns only the rows that are present in both result sets. This makes INTERSECT an essential clause when we need to find overlapping data between two or more queries.In this article, we will explain t
    5 min read
    SQL | EXISTS
    The SQL EXISTS condition is used to test whether a correlated subquery returns any results. If the subquery returns at least one row, the EXISTS condition evaluates to TRUE; otherwise, it evaluates to FALSE. The EXISTS operator can be used in various SQL statements like SELECT, UPDATE, INSERT, and D
    3 min read
    SQL CASE Statement
    The CASE statement in SQL is a versatile conditional expression that enables us to incorporate conditional logic directly within our queries. It allows you to return specific results based on certain conditions, enabling dynamic query outputs. Whether you need to create new columns, modify existing
    4 min read

    SQL Aggregate Functions

    SQL Aggregate functions
    SQL Aggregate Functions are used to perform calculations on a set of rows and return a single value. These functions are particularly useful when we need to summarize, analyze, or group large datasets in SQL databases. Whether you are working with sales data, employee records or product inventories,
    4 min read
    SQL COUNT(), AVG() and SUM() Function
    SQL aggregate functions, such as COUNT(), AVG(), and SUM(), are essential tools for performing mathematical analysis on data. These functions allow you to gather valuable insights from your database, such as calculating totals, and averages, and counting specific rows. In this article, we will expla
    3 min read
    SQL COUNT(), AVG() and SUM() Function
    SQL aggregate functions, such as COUNT(), AVG(), and SUM(), are essential tools for performing mathematical analysis on data. These functions allow you to gather valuable insights from your database, such as calculating totals, and averages, and counting specific rows. In this article, we will expla
    3 min read
    SQL MIN() and MAX() Functions
    The SQL MIN() and MAX() functions are essential aggregate functions in SQL used for data analysis. They allow you to extract the minimum and maximum values from a specified column, respectively, making them invaluable when working with numerical, string, or date-based data. In this article, we will
    4 min read
    SQL MIN() and MAX() Functions
    The SQL MIN() and MAX() functions are essential aggregate functions in SQL used for data analysis. They allow you to extract the minimum and maximum values from a specified column, respectively, making them invaluable when working with numerical, string, or date-based data. In this article, we will
    4 min read
    SQL COUNT(), AVG() and SUM() Function
    SQL aggregate functions, such as COUNT(), AVG(), and SUM(), are essential tools for performing mathematical analysis on data. These functions allow you to gather valuable insights from your database, such as calculating totals, and averages, and counting specific rows. In this article, we will expla
    3 min read

    SQL Data Constraints

    SQL NOT NULL Constraint
    In SQL, constraints are used to enforce rules on data, ensuring the accuracy, consistency, and integrity of the data stored in a database. One of the most commonly used constraints is the NOT NULL constraint, which ensures that a column cannot have NULL values. This is important for maintaining data
    3 min read
    SQL | UNIQUE Constraint
    In SQL, constraints play a vital role in maintaining the integrity and accuracy of the data stored in a database. One such constraint is the UNIQUE constraint, which ensures that all values in a column (or a combination of columns) are distinct, preventing duplicate entries. This constraint is espec
    4 min read
    SQL PRIMARY KEY Constraint
    The PRIMARY KEY constraint in SQL is one of the most important constraints used to ensure data integrity in a database table. A primary key uniquely identifies each record in a table, preventing duplicate or NULL values in the specified column(s). Understanding how to properly implement and use the
    5 min read
    SQL FOREIGN KEY Constraint
    A FOREIGN KEY constraint is a fundamental concept in relational databases, ensuring data integrity by enforcing relationships between tables. By linking a child table to a parent table, the foreign key establishes referential integrity. This constraint ensures that the values in the foreign key colu
    5 min read
    Composite Key in SQL
    A composite key is a primary key that is made up of more than one column to uniquely identify records in a table. Unlike a single-column primary key, a composite key combines two or more columns to ensure uniqueness. While any of the individual columns in a composite key might not be unique on their
    2 min read
    SQL | UNIQUE Constraint
    In SQL, constraints play a vital role in maintaining the integrity and accuracy of the data stored in a database. One such constraint is the UNIQUE constraint, which ensures that all values in a column (or a combination of columns) are distinct, preventing duplicate entries. This constraint is espec
    4 min read
    SQL - ALTERNATE KEY
    Alternate Key is any candidate key not selected as the primary key. So, while a table may have multiple candidate keys (sets of columns that could uniquely identify rows), only one of them is designated as the Primary Key. The rest of these candidate keys become Alternate Keys.In other words, we can
    4 min read
    SQL | CHECK Constraint
    In SQL, One such constraint is the CHECK constraint, which allows to enforcement of domain integrity by limiting the values that can be inserted or updated in a column. By using CHECK, we can define conditions on a column’s values and ensure that they adhere to specific rules.In this article, we wil
    5 min read
    SQL | DEFAULT Constraint
    In SQL, maintaining data integrity and ensuring consistency across tables is important for effective database management. One way to achieve this is by using constraints. Among the many types of constraints, the DEFAULT constraint plays an important role in automating data insertion and ensuring tha
    3 min read

    SQL Joining Data

    SQL Joins (Inner, Left, Right and Full Join)
    SQL joins are fundamental tools for combining data from multiple tables in relational databases. Joins allow efficient data retrieval, which is essential for generating meaningful observations and solving complex business queries. Understanding SQL join types, such as INNER JOIN, LEFT JOIN, RIGHT JO
    5 min read
    SQL Outer Join
    SQL Outer Joins allow retrieval of rows from two or more tables based on a related column. Unlike inner Joins, they also include rows that do not have a corresponding match in one or both of the tables. This capability makes Outer Joins extremely useful for comprehensive data analysis and reporting,
    4 min read
    SQL LEFT JOIN
    In SQL, LEFT JOIN retrieves all records from the left table and only the matching records from the right table. When there is no matching record found, NULL values are returned for columns from the right table. This makes LEFT JOIN extremely useful for queries where you need to retain all records fr
    5 min read
    SQL RIGHT JOIN
    In SQL, the RIGHT JOIN (also called RIGHT OUTER JOIN) is an essential command used to combine data from two tables based on a related column. It returns all records from the right table, along with the matching records from the left table. If there is no matching record in the left table, SQL will r
    3 min read
    SQL FULL JOIN
    In SQL, the FULL JOIN (or FULL OUTER JOIN) is a powerful technique used to combine records from two or more tables. Unlike an INNER JOIN, which only returns rows where there are matches in both tables, a FULL JOIN retrieves all rows from both tables, filling in NULL values where matches do not exist
    4 min read
    SQL CROSS JOIN
    In SQL, the CROSS JOIN is a unique join operation that returns the Cartesian product of two or more tables. This means it matches each row from the left table with every row from the right table, resulting in a combination of all possible pairs of records. In this article, we will learn the CROSS JO
    3 min read
    SQL Self Join
    A Self Join in SQL is a powerful technique that allows one to join a table with itself. This operation is helpful when you need to compare rows within the same table based on specific conditions. A Self Join is often used in scenarios where there is hierarchical or relational data within the same ta
    3 min read
    SQL | UPDATE with JOIN
    In SQL, the UPDATE with JOIN statement is a powerful tool that allows updating one table using data from another table based on a specific JOIN condition. This technique is particularly useful when we need to synchronize data, merge records, or update specific columns in one table by referencing rel
    4 min read
    SQL DELETE JOIN
    The SQL DELETE JOIN statement is a powerful feature that allows us to delete rows from one table based on conditions involving another table. This is particularly useful when managing relationships between tables in a database. For example, we may want to delete rows in a "Library Books" table where
    4 min read
    Recursive Join in SQL
    In SQL, a recursive join is a powerful technique used to handle hierarchical data relationships, such as managing employee-manager relationships, family trees, or any data with a self-referential structure. This type of join enables us to combine data from the same table repeatedly, accumulating rec
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences