
Your data, our passion.
Snack-Sized Data Basics
SQL - Select From

Now that we've added data to our table, let's look at how we retrieve the information we stored.
If you haven't already done so, create your table, and insert some data using the PostgreSQL database on sqliteonline.com. Refer back to the beginning of SQL - Data Insert Restrictions for reference.
​
Let's start by adding more data to practice with.
INSERT INTO students (first_name, last_name, date_of_birth, allergies)
VALUES
('Liam', 'Nguyen', '2015-07-22', 'None'),
('Sofia', 'Chen', '2013-09-10', 'Lactose'),
('Noah', 'Williams', '2014-03-18', 'Strawberries'),
('Mia', 'Robinson', '2015-11-02', 'None'),
('Lucas', 'Brown', '2013-06-27', 'Eggs'),
('Isabella', 'Garcia', '2014-08-14', 'Soy'),
('Ethan', 'Harris', '2015-01-08', 'Tree nuts'),
('Ava', 'Lopez', '2013-05-19', 'None'),
('Benjamin', 'Davis', '2014-11-11', 'Wheat'),
('Charlotte', 'Miller', '2015-02-23', 'Peanuts'),
('James', 'Wilson', '2013-10-03', 'None'),
('Amelia', 'Moore', '2014-07-01', 'Shellfish');
SELECT * FROM table_name;
To get all the information stored in a table, we use the following query.
In our case, using the students table, we can use the following.
SELECT * FROM students;
The asterisk * stands for "all". We're essentially saying, give me all rows and columns stored in the students table. ​
To get specific columns, we use the following query.
​​​​
SELECT column_name_1, column_name_2
FROM table;
​
In our case, an example would be:
​​​​​
SELECT first_name, last_name
FROM students;
​
To retrieve a specific number of rows, we use the following query.
​​​​
SELECT column_name_1, column_name_2
FROM table
LIMIT <number of rows desired>;
​
For example, if we wanted to get 5 rows, we'd use the following.
​​​​
SELECT first_name, last_name
FROM table
LIMIT 5;
​

Don't forget to practice!