UPPER

Text functions

SQLite in your browser
Lesson concept What you'll do
1 / 4

Join, cut and change text in a query.

|| joins text, SUBSTR cuts a piece out and UPPER makes capitals.

The database
9 rows
book_idtitleauthorgenreyearpages
1Pride and PrejudiceJane AustenRomance1813432
2The Great GatsbyF. Scott FitzgeraldFiction1925180
3DraculaBram StokerHorror1897418
4MockingjaySuzanne CollinsScience Fiction2010390
5The Time MachineH.G. WellsScience Fiction1895118
6Angels & DemonsDan BrownThriller2000616
7Charlotte's WebE.B. WhiteChildren1952184
8The Fault in Our StarsJohn GreenRomance2012313
9The Fellowship of the RingJ.R.R. TolkienFantasy1954423
Click a name to type it
Your query
 
Hint: click the green edit button on the board, or type it yourself
Query output Ready to run

Run your query to see the result table.

Press the green Run button or Ctrl+Enter.

Study notes

How UPPER, SUBSTR, || works

  • How do I join text?

    title || ' by ' || author

    || puts pieces of text together, like & in Excel. Your own text goes in single quotes.

  • What do UPPER and LOWER do?

    They change text to capitals or small letters: UPPER('Fantasy') gives FANTASY.

  • How do I cut text?

    SUBSTR(genre, 1, 3) takes 3 characters starting at character 1, like MID in Excel. LENGTH(title) counts the characters, like LEN.

  • What else is there?

    TRIM removes spaces at the ends, REPLACE(title, 'The ', '') swaps text, and INSTR(title, ' ') finds where a space is, like FIND.

  • What happens with NULL?

    'Series: ' || series is NULL when series is NULL. Use COALESCE(series, 'none') to fill the gap first.

Other databases

How other databases do it

The lessons run on SQLite. Most of SQL is the same everywhere; these are the places where this lesson's SQL differs.

Joining text
DatabaseHowNote
SQLite (these lessons)title || ' by ' || author
PostgreSQLtitle || ' by ' || authorCONCAT(title, ' by ', author) also works and skips NULLs.
MySQL / MariaDBCONCAT(title, ' by ', author)|| means OR in MySQL unless PIPES_AS_CONCAT is on.
SQL Servertitle + ' by ' + authorOr CONCAT(...) since SQL Server 2012.
Oracletitle || ' by ' || authorCONCAT takes only two pieces in Oracle.
Sybase ASEtitle + ' by ' + author
Cutting text and counting characters
DatabaseHowNote
SQLite (these lessons)SUBSTR(genre, 1, 3), LENGTH(title)SUBSTRING works too since SQLite 3.34.
PostgreSQLSUBSTRING(genre, 1, 3), LENGTH(title)SUBSTR works too.
MySQL / MariaDBSUBSTRING(genre, 1, 3), CHAR_LENGTH(title)LENGTH counts bytes, so accented letters count double.
SQL ServerSUBSTRING(genre, 1, 3), LEN(title)LEN ignores spaces at the end. LEFT(genre, 3) also works.
OracleSUBSTR(genre, 1, 3), LENGTH(title)
Sybase ASESUBSTRING(genre, 1, 3), CHAR_LENGTH(title)

Know someone fighting with a spreadsheet? Send them this page.