What are some other useful things that SQL lets us do?

Question

In the context of this exercise, what are some other useful things that SQL lets us do?

Answer

SQL provides us with a lot of useful functionality for interacting with databases.

When retrieving data from a database, we can use SQL to select specific rows based on some condition. For example, this will retrieve just the rows that satisfy the condition following the WHERE clause, which is when the value under the col column is greater than 50.

SELECT col FROM table
WHERE col > 50;

SQL also lets us aggregate data, which means to summarize observations for groups of data. For example, SQL provides aggregate functions to get the sum or the average of all values of a column, returning a single value, or summary.

In addition, we can even combine multiple tables using the JOIN clause. We can combine tables by essentially stacking all the rows of one table on top of the other, or we can combine them based on some conditions or on matching values of some columns only.

These are only a few of the many useful features that SQL provides. Feel free to check out some SQL documentation or the Codecademy SQL courses for more useful things that SQL lets us do!

12 Likes

With this same logic I tried to select only females in the database but I couldn’t figure out how. I tried:

SELECT gender FROM table
WHERE gender += female;

and

SELECT gender FROM users
WHERE gender += female;

and

SELECT female FROM users;

No luck :frowning: How would i go about selecting specific users based on their info?

1 Like

To select only females, you would write:

SELECT * FROM users
WHERE gender = ‘Female’;

This will first return all (*) columns from the ‘users’ table,
then it will only return rows where the gender column has a value of ‘Female’ (make sure to wrap Female in quotes (’’), as Female is of the string data type

4 Likes

How would i select only users with emails containing ‘facebook.com’ ?

You can use something like

WHERE “email” LIKE ‘%facebook.com

I am quite new to this, but the ‘%’ is what you want to use in this situation.

1 Like

How do you do multiple data selection criteria, example I want to do this:

SELECT * FROM users
WHERE membership_id <= ‘2000’;
WHERE gender = ‘Male’;

use AND or OR, depending if you want both or one of the conditions to be met

2 Likes