Skip to content

SQL, how to use SELECT

New Course Coming Soon:

Get Really Good at Git

How to get data from a SQL database table

You can get data out of tables using the SELECT command.

Get all rows and columns:

SELECT * FROM people;
 age |  name  
-----+--------
  37 | Flavio
   8 | Roger

Get only the name column:

SELECT name FROM people;
  name  
--------
 Flavio
 Roger

Count the items in the table:

SELECT COUNT(*) from people;
 count 
-------
     2

You can filter rows in a table adding the WHERE clause:

SELECT age FROM people WHERE name='Flavio';
 age 
-----
  37

The results of a query can be ordered by column value, ascending (the default) or descending, using ORDER BY:

SELECT * FROM people ORDER BY name;
SELECT * FROM people ORDER BY name DESC;
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!
→ Read my SQL Tutorial on The Valley of Code

Here is how can I help you: