0% found this document useful (0 votes)
20 views

Manipulating Strings in SQL

This document discusses string manipulation functions in SQL, including CONCAT, CONCAT_WS, and CONCAT with the + operator. CONCAT combines two or more strings together without spaces, CONCAT_WS adds strings with a separator, and CONCAT with + also combines strings. Examples show how each function can be used to concatenate strings like 'Data' and 'analysis' into the single string 'Data analysis'. The document recommends practicing with these functions on W3Schools for interactive SQL learning.

Uploaded by

haseeb2597
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Manipulating Strings in SQL

This document discusses string manipulation functions in SQL, including CONCAT, CONCAT_WS, and CONCAT with the + operator. CONCAT combines two or more strings together without spaces, CONCAT_WS adds strings with a separator, and CONCAT with + also combines strings. Examples show how each function can be used to concatenate strings like 'Data' and 'analysis' into the single string 'Data analysis'. The document recommends practicing with these functions on W3Schools for interactive SQL learning.

Uploaded by

haseeb2597
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Manipulating strings in SQL

Knowing how to convert and manipulate your data for an accurate analysis is an important part of
a data analyst’s job. In this reading, you will learn about different SQL functions and their usage,
especially regarding string combinations.

A string is a set of characters that helps to declare the texts in programming languages such as
SQL. SQL string functions are used to obtain various information about the characters, or in this
case, manipulate them. One such function, CONCAT, is commonly used. Review the table below
to learn more about the CONCAT function and its variations.

Function Usage Example


A function that adds strings together to
CONCAT create new text strings that can be used CONCAT (‘Google’, ‘.com’);
as unique keys
CONCAT_WS (‘ . ’, ‘www’, ‘google’, ‘com’) *Th
A function that adds two or more strings
CONCAT_WS (being the period) gets input before and after Googl
together with a separator
run the SQL function
CONCAT with Adds two or more strings together using
‘Google’ + ‘.com’
+ the + operator
CONCAT at work
When adding two strings together such as ‘Data’ and ‘analysis’, it will be input like this:

 SELECT CONCAT (‘Data’, ‘analysis’);


The result will be:

 Dataanalysis
Sometimes, depending on the strings, you will need to add a space character, so your function
should actually be:

 SELECT CONCAT (‘Data’, ‘ ‘, ‘analysis’);


And the result will be:

 Data analysis
The same rule applies when combining three strings together. For example,

 SELECT CONCAT (‘Data’,’ ‘, ‘analysis’, ‘ ‘, ‘is’, ‘ ‘, ‘awesome!’);


And the result will be

 Data analysis is awesome!

Practice makes perfect


W3 Schools is an excellent resource for interactive SQL learning, and the following links will
guide you through transforming your data using SQL:

 SQL functions: This is a comprehensive list of functions to get you started. Click on each
function, where you will learn about the definition, usage, examples, and even be able to
create and run your own query for practice. Try it out for yourself!
 SQL Keywords: This is a helpful SQL keywords reference to bookmark as you increase
your knowledge of SQL. This list of keywords are reserved words that you will use as
your need to perform different operations in the database grows.
 While this reading went through the basics of each of these functions, there is still more
to learn, and you can even combine your own strings.
1. Practice using CONCAT
2. Practice using CONCAT WS
3. Practice using CONCAT with +
Pro tip: The functions presented in the resources above may be applied in slightly different ways
depending on the database that you are using (e.g. mySQL versus SQL Server). But, the general
description provided for each function will prepare you to customize how you use these functions
as neede

You might also like