Back to articles list November 20, 2020 - 5 minutes read How To Learn The SELECT Statement in SQL Adrian Więch Adrian is an active software developer focused on Java and SQL-related technologies. He holds a Master’s Degree in both Computer Science and Applied Linguistics. While most people focus on specialization, he goes against the flow and believes that diversity is key to personal development. You’ll find him weightlifting, playing the piano, studying psychology and travelling around the world. Tags: sql learn sql sql basics online practice SELECT When you think about learning SQL, one of the first things you come across is the SELECT statement. Selecting information is arguably the most important SQL feature. In this article, we’ll demonstrate the typical use cases for SQL SELECT with practical examples. Read this article if you’re a beginner database user and would like to know what SELECT can do for you. SQL, or Structured Query Language, is the programming language the IT world uses to communicate with databases. It first appeared in 1974, and has been in widespread use ever since. If you’re reading this article, you’re probably thinking about learning SQL, or you’ve just started your adventure with databases. In this article, we’ll explain how you can use the SQL SELECT statement, which is probably one of the most important SQL aspects. New to databases and SQL? Before continuing with the article, you can also take a look at two short YouTube videos that we’ve prepared. First, watch our video about databases. Once you’re through, have a look at another video that explains what SQL is. Hello World of SQL Whenever people go about studying a new programming language, they typically start with a metaphorical “Hello World” example that demonstrates the simplest instruction that can actually do something useful. What would that instruction be in SQL? Imagine we have a table in our database that contains some basic information about SQL enthusiasts. The table looks like this: Table name: sql_enthusiast first_namecountryyear_born JohnUK1974 PiotrPoland1985 RaquelArgentina1992 AikoJapan1960 In the world of SQL, the very first example for this table would be as follows: SELECT * FROM sql_enthusiast; Let’s break this example down: SELECT is an SQL keyword which indicates what we want to show (retrieve). * (asterisk) means “everything, all columns”. FROM is another SQL keyword which indicates the table(s) (i.e. the source of the data we need). sql_enthusiast is the name of the table we retrieve the data from. This instruction in the world of databases means “show all data from table sql_enthusiast”. You can see that this query already contains the SELECT statement, which is the command used to retrieve, or show, information from database tables. As a result, our database will produce something along the lines of: first_name | country | year_born ------------+-----------+---------- John | UK | 1974 Piotr | Poland | 1985 Raquel | Argentina | 1992 Aiko | Japan | 1960 In the example above, we used the asterisk sign (*) to show all the information from the table. However, we can also be more specific. Instead of the asterisk, we can provide a specific column name: SELECT first_name FROM sql_enthusiast; The instruction above is similar to the previous one. However, instead of SELECT *, which meant “show all columns”, we use SELECT first_name, which means: “select the column first_name”. The instruction above means “show all first names from the table sql_enthusiast”. As a result, we’ll see the following: first_name ----------- John Piotr Raquel Aiko Not so complicated, right? We can also specify more than one column to select (show) by separating the column names with commas: SELECT first_name, year_born FROM sql_enthusiast; This time, SELECT first_name, year_born means “select columns first_name and year_born”. The entire SQL query will show all first names alongside the corresponding birth years from the table sql_enthusiast. When we run this instruction in our database, we’ll get something like this in return: first_name | year_born -----------+---------- John | 1974 Piotr | 1985 Raquel | 1992 Aiko | 1960 More Advanced SELECT Usages Judging from the examples above, the SQL SELECT statement may look pretty simple and straightforward to use. However, it can also come in handy in more complex queries. The SELECT statement can compute statistics for tables or groups of rows. How many SQL enthusiasts are there in our database? What is their average age? Who’s the oldest SQL enthusiast, and who’s the youngest? All of these questions can be answered with proper SELECT instructions. Apart from statistics for entire tables or groups of rows, we can use various functions and perform calculations in the SELECT clause too. What’s the date today? How many days have passed since a given date? For a table with product prices, what are the product prices before and after tax? What’s the difference between two columns? SQL SELECT can handle all of these situations too. In more advanced cases, the SELECT statement can even be used to filter rows based on complex conditions, join information from multiple tables, or present running averages. Where To Learn SQL SELECT? If you’d like to become fluent in SQL and learn how to use the SELECT statement and other SQL elements, we’ve got you covered. LearnSQL.com is a platform to learn SQL all by yourself from scratch. We teach you to use the database language in a completely interactive manner. If you’re a beginner or you’ve never written an SQL instruction before, have a look at our best-selling SQL Basics course. It will take you from zero to an intermediate SQL user in around 10 hours. If time is at stake, you can also read our article entitled How Long Does It Take to Learn SQL. If you’d like to find out more about the benefits of learning with us before you enroll, take a look at this article: Why Take the SQL Basics Course at LearnSQL.com. It explains in detail why we have built the course, what it contains and what you can expect inside. And if you have difficulties remembering the SQL keywords and syntax, we’ve prepared an SQL cheat sheet which you can download for free! It is available here: SQL Basics Cheat Sheet. Summary The SELECT statement is by far the most widely used SQL command when retrieving information from databases. Even though its main purpose is to show information from tables, it can also do much more than that. We hope this article gave you a good overview of the potential hidden in this SQL instruction. Tags: sql learn sql sql basics online practice SELECT You may also like How to Study Online: 5 Steps to Becoming an Effective Learner Want to learn how to study online more effectively? Check out our 5 steps guide for online learners. Read more Learning SQL for Free – Is It Worth Betting on Free Online Learning? Want to learn SQL for free? See where you can find free online courses and how to choose the perfect one for you. Read more New LearnSQL.com Online Practice – Solve Basic SQL Questions with the SQL Practice Set We created our SQL practice set to help you master your SQL skills. Get access to our SQL online practice exercises for free! Read more Top 3 Platforms to Learn SQL Online: A Complete Comparison What is the best place to learn SQL online? It is hard to choose without enough information. I tested and compared 3 major platforms to help you decide. Read more Video Tutorial or Interactive SQL Course – Which Is Better? Decide what SQL learning method will be best for you - tutorial or course. Don't waste your time or money! Read more Learning SQL? 12 Ways to Practice SQL Online Want to learn SQL or practice SQL online? We’ve rounded up the top ways to practice SQL so you can go from learning to earning! Read more Subscribe to our newsletter Join our weekly newsletter to be notified about the latest posts.