This page allows you to practice SQL online, and provides more than 200 different SQL exercises and solutions. This platform is also accompanied by a self-study guide, which offers comprehensive coverage of the SQL language, in a detailed, logical and well organized manner.
We hope you’ll find this page useful and effective.
Ram Kedem and Elad Peleg.
In General :
- Please note Rextester requires a small fee in order to use it
- Use this section to practice Microsoft / Oracle related SQL exercises
- The Microsoft related tutorials / exercises can found in this link
The Oracle related tutorials / exercises can be found in this link - To download the databases used in these exercises, use one of the following links: [ACDB] [HR]
- Please note – Exercises performed on the online environment, might return less results than those performed on your local environment (by downloading ACDB or HR to your local machine). The platform I used to create this online SQL practice has a limit for the maximum number of rows in each database, therefore in each table you’ll find only sample rows of data.
How To :
Rextester stands for regular expression tester. Using Rextester.com you’ll be able to issue online queries against Microsoft / Oracle databases.
Working with this platform is quite easy, use the following link to access the online SQL editor, use the top-left drop down list to choose your platform.
Once you’re there, copy the contents of either [ACDB] or [HR] scripts:
And that’s it, you’re ready to go. Issue any query against the database. (Type your query at the bottom of the script)
The following questions allow you to practice SQL online using the Stack Overflow Data Explorer.
The Stack Overflow Data Explorer is a free utility allowing you to learn SQL interactively by querying the data of Stack Overflow Q&A for programmers.
Very important
Most of the tables of Stack Overflow Data Explorer contain great amount of rows. Querying the whole table will slow you down significantly, and most importantly – will overload the database server.
Please, use the TOP command in every SQL statement you issue, and retrieve back only partial results.
You will be reminded to so that in every exercise
Practice SQL Online – Basic SQL Select Statments
- Create a query to display all data from the Posts table. Remember to use TOP 20.
SELECT TOP 20 * FROM posts
- Create a query to display all the data from the Users table. Remember to use TOP 20.
SELECT TOP 20 * FROM users
- The following SELECT statement executes successfully (True / False)
FROM Posts SELECT PostTypeId, AnswerCount
False.
- Create a query to display the AnswerCount, ViewCount, and Title. Name the last column (Title) heading as “Post Title” (Posts table). Remember to use TOP 20.
SELECT TOP 20 AnswerCount, ViewCount, Title AS "Post Title" FROM posts
- The following SELECT statement executes successfully (True / False)
SELECT TOP 20 Id, Views, Views FROM Users
True
- The following SELECT statement executes successfully (True / False)
SeleCT TOP 20 PostTypeId, AnswerCount, FROM Posts
False
- Create a query to display the post id, ViewCount, Title, AnswerCount and CreationDate (Posts table). Remember to use TOP 20.
SELECT TOP 20 id, ViewCount, Title, AnswerCount, CreationDate FROM posts
- Create a query to display the Title, Body, CreationDate, AnswerCount, and FavoriteCount after an addition of 20%. Name the last column (FavoriteCount after the addition) heading as “New Count” (Posts table). Remember to use TOP 20.
SELECT TOP 20 Title, Body, CreationDate, AnswerCount, FavoriteCount * 1.2 AS 'New Count' FROM posts
- Create a query to display the Body concatenated with the Title, separated by space, and the literal ‘Tag List : ‘ concatenated with the values of Tags column. Name the column headings “Post Details” and “Tags” respectively (Posts table). Remember to use T0P 20.
SELECT TOP 20 Body + ' ' + Title AS 'Post Details', 'Tag List : ' + Tags AS 'Tags' FROM Posts
- Create a query to display the unique PostTypeId from Posts table.
SELECT DISTINCT PostTypeId FROM posts
- Create a query to display the Body concatenated with Tags column, separated by space. Name this column heading as “Body and Tags” (Posts table). Remember to use TOP 20.
SELECT Body + ' ' + Tags AS 'Body and Tags' FROM posts
- Create a query to display the Title, Body, and AnswerCount, also display the Score column concatenated with the literal string “SCn”, separated by space.
Name the column headings “TL”, “BD”, “AC”, and “SC” respectively (Posts table).
Note that the Score column datatype is numeric, and in order to concatenate it with a string you need to use the CAST function.
Remember to use TOP 20.
SELECT TOP 20 Title AS 'TL', Body AS 'BD' , AnswerCount AS 'AC' , CAST(Score AS VARCHAR) + ' SCn' AS 'SC' FROM Posts
- Create a query to display the unique ReviewTaskTypeId in ReviewTasks table. TOP statement cannot be used in this exercise.
SELECT DISTINCT ReviewTaskTypeId FROM ReviewTasks