mysql

Introduction

Databases are a key component of many websites and applications, and are at the core of how data is stored and exchanged across the internet. One of the most important aspects of database management is the practice of retrieving data from a database, whether it’s on an ad hoc basis or part of a process that’s been coded into an application. There are several ways to retrieve information from a database, but one of the most commonly-used methods is performed through submitting queries through the command line.

In relational database management systems, a query is any command used to retrieve data from a table. In Structured Query Language (SQL), queries are almost always made using the SELECT statement.

In this guide, we will discuss the basic syntax of SQL queries as well as some of the more commonly-employed functions and operators. We will also practice making SQL queries using some sample data in a MySQL database.

MySQL is an open-source relational database management system. One of the most widely-deployed SQL-databases, MySQL prioritizes speed, reliability, and usability. It generally follows the ANSI SQL standard, although there are a few cases where MySQL performs operations differently than the recognized standard.

Prerequisites

In general, the commands and concepts presented in this guide can be used on any Linux-based operating system running any SQL database software. However, it was written specifically with an Ubuntu 18.04 server running MySQL in mind. To set this up, you will need the following:

With this setup in place, we can begin the tutorial.

Creating a Sample Database

Before we can begin making queries in SQL, we will first create a database and a couple tables, then populate these tables with some sample data. This will allow you to gain some hands-on experience when you begin making queries later on.

For the sample database we’ll use throughout this guide, imagine the following scenario:

You and several of your friends all celebrate your birthdays with one another. On each occasion, the members of the group head to the local bowling alley, participate in a friendly tournament, and then everyone heads to your place where you prepare the birthday-person’s favorite meal.

Now that this tradition has been going on for a while, you’ve decided to begin tracking the records from these tournaments. Also, to make planning dinners easier, you decide to create a record of your friends’ birthdays and their favorite entrees, sides, and desserts. Rather than keep this information in a physical ledger, you decide to exercise your database skills by recording it in a MySQL database.

To begin, open up a MySQL prompt as your root MySQL user:

  • sudo mysql

Note: If you followed the prerequisite the tutorial on Installing MySQL on Ubuntu 18.04, you may have configured your root user to authenticate using a password. In this case, you will connect to the MySQL prompt with the following command:

  • mysql -u root -p

Next, create the database by running:

  • CREATE DATABASE `birthdays`;

Then select this database by typing:

  • USE birthdays;

Next, create two tables within this database. We’ll use the first table to track your friends’ records at the bowling alley. The following command will create a table called tourneys with columns for the name of each of your friends, the number of tournaments they’ve won (wins), their all-time best score, and what size bowling shoe they wear (size):

  • CREATE TABLE tourneys (
  • name varchar(30),
  • wins real,
  • best real,
  • size real
  • );

Once you run the CREATE TABLE command and populate it with column headings, you’ll receive the following output:

Output
Query OK, 0 rows affected (0.00 sec)

Populate the tourneys table with some sample data:

  • INSERT INTO tourneys (name, wins, best, size)
  • VALUES (‘Dolly’, ‘7’, ‘245’, ‘8.5’),
  • (‘Etta’, ‘4’, ‘283’, ‘9’),
  • (‘Irma’, ‘9’, ‘266’, ‘7’),
  • (‘Barbara’, ‘2’, ‘197’, ‘7.5’),
  • (‘Gladys’, ’13’, ‘273’, ‘8’);

You’ll receive an output like this:

Output
Query OK, 5 rows affected (0.01 sec)
Records: 5  Duplicates: 0  Warnings: 0

Following this, create another table within the same database which we’ll use to store information about your friends’ favorite birthday meals. The following command creates a table named dinners with columns for the name of each of your friends, their birthdate, their favorite entree, their preferred side dish, and their favorite dessert:

  • CREATE TABLE dinners (
  • name varchar(30),
  • birthdate date,
  • entree varchar(30),
  • side varchar(30),
  • dessert varchar(30)
  • );

Similarly for this table, you’ll receive feedback confirming that the command ran successfully:

Output
Query OK, 0 rows affected (0.01 sec)

Populate this table with some sample data as well:

  • INSERT INTO dinners (name, birthdate, entree, side, dessert)
  • VALUES (‘Dolly’, ‘1946-01-19’, ‘steak’, ‘salad’, ‘cake’),
  • (‘Etta’, ‘1938-01-25’, ‘chicken’, ‘fries’, ‘ice cream’),
  • (‘Irma’, ‘1941-02-18’, ‘tofu’, ‘fries’, ‘cake’),
  • (‘Barbara’, ‘1948-12-25’, ‘tofu’, ‘salad’, ‘ice cream’),
  • (‘Gladys’, ‘1944-05-28’, ‘steak’, ‘fries’, ‘ice cream’);
Output
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

Once that command completes successfully, you’re done setting up your database. Next, we’ll go over the basic command structure of SELECT queries.

Understanding SELECT Statements

As mentioned in the introduction, SQL queries almost always begin with the SELECT statement. SELECT is used in queries to specify which columns from a table should be returned in the result-set. Queries also almost always include FROM, which is used to specify which table the statement will query.

Generally, SQL queries follow this syntax:

  • SELECT column_to_select FROM table_to_select WHERE certain_conditions_apply;

By way of example, the following statement will return the entire name column from the dinners table:

  • SELECT name FROM dinners;
Output
+---------+
| name    |
+---------+
| Dolly   |
| Etta    |
| Irma    |
| Barbara |
| Gladys  |
+---------+
5 rows in set (0.00 sec)

You can select multiple columns from the same table by separating their names with a comma, like this:

  • SELECT name, birthdate FROM dinners;
Output
+---------+------------+
| name    | birthdate  |
+---------+------------+
| Dolly   | 1946-01-19 |
| Etta    | 1938-01-25 |
| Irma    | 1941-02-18 |
| Barbara | 1948-12-25 |
| Gladys  | 1944-05-28 |
+---------+------------+
5 rows in set (0.00 sec)

Instead of naming a specific column or set of columns, you can follow the SELECT operator with an asterisk (*) which serves as a placeholder representing all the columns in a table. The following command returns every column from the tourneys table:

  • SELECT * FROM tourneys;
Output
+---------+------+------+------+
| name    | wins | best | size |
+---------+------+------+------+
| Dolly   |    7 |  245 |  8.5 |
| Etta    |    4 |  283 |    9 |
| Irma    |    9 |  266 |    7 |
| Barbara |    2 |  197 |  7.5 |
| Gladys  |   13 |  273 |    8 |
+---------+------+------+------+
5 rows in set (0.00 sec)

WHERE is used in queries to filter records that meet a specified condition, and any rows that do not meet that condition are eliminated from the result. A WHERE clause typically follows this syntax:

  • . . . WHERE column_name comparison_operator value

The comparison operator in a WHERE clause defines how the specified column should be compared against the value. Here are some common SQL comparison operators:

ALSO READ  Voter Registration: Onitsha South LG Chairman's Aide Tours Wards, Commends INEC, Constituents
Operator What it does
= tests for equality
!= tests for inequality
< tests for less-than
> tests for greater-than
<= tests for less-than or equal-to
>= tests for greater-than or equal-to
BETWEEN tests whether a value lies within a given range
IN tests whether a row’s value is contained in a set of specified values
EXISTS tests whether rows exist, given the specified conditions
LIKE tests whether a value matches a specified string
IS NULL tests for NULL values
IS NOT NULL tests for all values other than NULL

For example, if you wanted to find Irma’s shoe size, you could use the following query:

  • SELECT size FROM tourneys WHERE name = ‘Irma’;
Output
+------+
| size |
+------+
|    7 |
+------+
1 row in set (0.00 sec)

SQL allows the use of wildcard characters, and these are especially handy when used in WHERE clauses. Percentage signs (%) represent zero or more unknown characters, and underscores (_) represent a single unknown character. These are useful if you’re trying to find a specific entry in a table, but aren’t sure of what that entry is exactly. To illustrate, let’s say that you’ve forgotten the favorite entree of a few of your friends, but you’re certain this particular entree starts with a “t.” You could find its name by running the following query:

  • SELECT entree FROM dinners WHERE entree LIKE ‘t%’;
Output
+--------+
| entree |
+--------+
| tofu   |
| tofu   |
+--------+
2 rows in set (0.00 sec)

Based on the output above, we see that the entree we have forgotten is tofu.

There may be times when you’re working with databases that have columns or tables with relatively long or difficult-to-read names. In these cases, you can make these names more readable by creating an alias with the AS keyword. Aliases created with AS are temporary, and only exist for the duration of the query for which they’re created:

  • SELECT name AS n, birthdate AS b, dessert AS d FROM dinners;
Output
+---------+------------+-----------+
| n       | b          | d         |
+---------+------------+-----------+
| Dolly   | 1946-01-19 | cake      |
| Etta    | 1938-01-25 | ice cream |
| Irma    | 1941-02-18 | cake      |
| Barbara | 1948-12-25 | ice cream |
| Gladys  | 1944-05-28 | ice cream |
+---------+------------+-----------+
5 rows in set (0.00 sec)

Here, we have told SQL to display the name column as n, the birthdate column as b, and the dessert column as d.

The examples we’ve gone through up to this point include some of the more frequently-used keywords and clauses in SQL queries. These are useful for basic queries, but they aren’t helpful if you’re trying to perform a calculation or derive a scalar value (a single value, as opposed to a set of multiple different values) based on your data. This is where aggregate functions come into play.

Aggregate Functions

Oftentimes, when working with data, you don’t necessarily want to see the data itself. Rather, you want information about the data. The SQL syntax includes a number of functions that allow you to interpret or run calculations on your data just by issuing a SELECT query. These are known as aggregate functions.

The COUNT function counts and returns the number of rows that match a certain criteria. For example, if you’d like to know how many of your friends prefer tofu for their birthday entree, you could issue this query:

  • SELECT COUNT(entree) FROM dinners WHERE entree = ‘tofu’;
Output
+---------------+
| COUNT(entree) |
+---------------+
|             2 |
+---------------+
1 row in set (0.00 sec)

The AVG function returns the average (mean) value of a column. Using our example table, you could find the average best score amongst your friends with this query:

  • SELECT AVG(best) FROM tourneys;
Output
+-----------+
| AVG(best) |
+-----------+
|     252.8 |
+-----------+
1 row in set (0.00 sec)

SUM is used to find the total sum of a given column. For instance, if you’d like to see how many games you and your friends have bowled over the years, you could run this query:

  • SELECT SUM(wins) FROM tourneys;
Output
+-----------+
| SUM(wins) |
+-----------+
|        35 |
+-----------+
1 row in set (0.00 sec)

Note that the AVG and SUM functions will only work correctly when used with numeric data. If you try to use them on non-numerical data, it will result in either an error or just 0, depending on which RDBMS you’re using:

  • SELECT SUM(entree) FROM dinners;
Output
+-------------+
| SUM(entree) |
+-------------+
|           0 |
+-------------+
1 row in set, 5 warnings (0.00 sec)

MIN is used to find the smallest value within a specified column. You could use this query to see what the worst overall bowling record is so far (in terms of number of wins):

  • SELECT MIN(wins) FROM tourneys;
Output
+-----------+
| MIN(wins) |
+-----------+
|         2 |
+-----------+
1 row in set (0.00 sec)

Similarly, MAX is used to find the largest numeric value in a given column. The following query will show the best overall bowling record:

  • SELECT MAX(wins) FROM tourneys;
Output
+-----------+
| MAX(wins) |
+-----------+
|        13 |
+-----------+
1 row in set (0.00 sec)

Unlike SUM and AVG, the MIN and MAX functions can be used for both numeric and alphabetic data types. When run on a column containing string values, the MIN function will show the first value alphabetically:

  • SELECT MIN(name) FROM dinners;
Output
+-----------+
| MIN(name) |
+-----------+
| Barbara   |
+-----------+
1 row in set (0.00 sec)

Likewise, when run on a column containing string values, the MAX function will show the last value alphabetically:

  • SELECT MAX(name) FROM dinners;
Output
+-----------+
| MAX(name) |
+-----------+
| Irma      |
+-----------+
1 row in set (0.00 sec)

Aggregate functions have many uses beyond what was described in this section. They’re particularly useful when used with the GROUP BY clause, which is covered in the next section along with several other query clauses that affect how result-sets are sorted.

Manipulating Query Outputs

In addition to the FROM and WHERE clauses, there are several other clauses which are used to manipulate the results of a SELECT query. In this section, we will explain and provide examples for some of the more commonly-used query clauses.

One of the most frequently-used query clauses, aside from FROM and WHERE, is the GROUP BY clause. It’s typically used when you’re performing an aggregate function on one column, but in relation to matching values in another.

ALSO READ  2023 UMUERI NEW YAM FESTIVAL;MONARCH COMMENDS GOVERNOR SOLUDO'S FREE EDUCATION POLICY

For example, let’s say you wanted to know how many of your friends prefer each of the three entrees you make. You could find this info with the following query:

  • SELECT COUNT(name), entree FROM dinners GROUP BY entree;
Output
+-------------+---------+
| COUNT(name) | entree  |
+-------------+---------+
|           1 | chicken |
|           2 | steak   |
|           2 | tofu    |
+-------------+---------+
3 rows in set (0.00 sec)

The ORDER BY clause is used to sort query results. By default, numeric values are sorted in ascending order, and text values are sorted in alphabetical order. To illustrate, the following query lists the name and birthdate columns, but sorts the results by birthdate:

  • SELECT name, birthdate FROM dinners ORDER BY birthdate;
Output
+---------+------------+
| name    | birthdate  |
+---------+------------+
| Etta    | 1938-01-25 |
| Irma    | 1941-02-18 |
| Gladys  | 1944-05-28 |
| Dolly   | 1946-01-19 |
| Barbara | 1948-12-25 |
+---------+------------+
5 rows in set (0.00 sec)

Notice that the default behavior of ORDER BY is to sort the result-set in ascending order. To reverse this and have the result-set sorted in descending order, close the query with DESC:

  • SELECT name, birthdate FROM dinners ORDER BY birthdate DESC;
Output
+---------+------------+
| name    | birthdate  |
+---------+------------+
| Barbara | 1948-12-25 |
| Dolly   | 1946-01-19 |
| Gladys  | 1944-05-28 |
| Irma    | 1941-02-18 |
| Etta    | 1938-01-25 |
+---------+------------+
5 rows in set (0.00 sec)

As mentioned previously, the WHERE clause is used to filter results based on specific conditions. However, if you use the WHERE clause with an aggregate function, it will return an error, as is the case with the following attempt to find which sides are the favorite of at least three of your friends:

  • SELECT COUNT(name), side FROM dinners WHERE COUNT(name) >= 3;
Output
ERROR 1111 (HY000): Invalid use of group function

The HAVING clause was added to SQL to provide functionality similar to that of the WHERE clause while also being compatible with aggregate functions. It’s helpful to think of the difference between these two clauses as being that WHERE applies to individual records, while HAVING applies to group records. To this end, any time you issue a HAVING clause, the GROUP BY clause must also be present.

The following example is another attempt to find which side dishes are the favorite of at least three of your friends, although this one will return a result without error:

  • SELECT COUNT(name), side FROM dinners GROUP BY side HAVING COUNT(name) >= 3;
Output
+-------------+-------+
| COUNT(name) | side  |
+-------------+-------+
|           3 | fries |
+-------------+-------+
1 row in set (0.00 sec)

Aggregate functions are useful for summarizing the results of a particular column in a given table. However, there are many cases where it’s necessary to query the contents of more than one table. We’ll go over a few ways you can do this in the next section.

Querying Multiple Tables

More often than not, a database contains multiple tables, each holding different sets of data. SQL provides a few different ways to run a single query on multiple tables.

The JOIN clause can be used to combine rows from two or more tables in a query result. It does this by finding a related column between the tables and sorts the results appropriately in the output.

SELECT statements that include a JOIN clause generally follow this syntax:

  • SELECT table1.column1, table2.column2
  • FROM table1
  • JOIN table2 ON table1.related_column=table2.related_column;

Note that because JOIN clauses compare the contents of more than one table, the previous example specifies which table to select each column from by preceding the name of the column with the name of the table and a period. You can specify which table a column should be selected from like this for any query, although it’s not necessary when selecting from a single table, as we’ve done in the previous sections. Let’s walk through an example using our sample data.

Imagine that you wanted to buy each of your friends a pair of bowling shoes as a birthday gift. Because the information about your friends’ birthdates and shoe sizes are held in separate tables, you could query both tables separately then compare the results from each. With a JOIN clause, though, you can find all the information you want with a single query:

  • SELECT tourneys.name, tourneys.size, dinners.birthdate
  • FROM tourneys
  • JOIN dinners ON tourneys.name=dinners.name;
Output
+---------+------+------------+
| name    | size | birthdate  |
+---------+------+------------+
| Dolly   |  8.5 | 1946-01-19 |
| Etta    |    9 | 1938-01-25 |
| Irma    |    7 | 1941-02-18 |
| Barbara |  7.5 | 1948-12-25 |
| Gladys  |    8 | 1944-05-28 |
+---------+------+------------+
5 rows in set (0.00 sec)

The JOIN clause used in this example, without any other arguments, is an inner JOIN clause. This means that it selects all the records that have matching values in both tables and prints them to the results set, while any records that aren’t matched are excluded. To illustrate this idea, let’s add a new row to each table that doesn’t have a corresponding entry in the other:

  • INSERT INTO tourneys (name, wins, best, size)
  • VALUES (‘Bettye’, ‘0’, ‘193’, ‘9’);
  • INSERT INTO dinners (name, birthdate, entree, side, dessert)
  • VALUES (‘Lesley’, ‘1946-05-02’, ‘steak’, ‘salad’, ‘ice cream’);

Then, re-run the previous SELECT statement with the JOIN clause:

  • SELECT tourneys.name, tourneys.size, dinners.birthdate
  • FROM tourneys
  • JOIN dinners ON tourneys.name=dinners.name;
Output
+---------+------+------------+
| name    | size | birthdate  |
+---------+------+------------+
| Dolly   |  8.5 | 1946-01-19 |
| Etta    |    9 | 1938-01-25 |
| Irma    |    7 | 1941-02-18 |
| Barbara |  7.5 | 1948-12-25 |
| Gladys  |    8 | 1944-05-28 |
+---------+------+------------+
5 rows in set (0.00 sec)

Notice that, because the tourneys table has no entry for Lesley and the dinners table has no entry for Bettye, those records are absent from this output.

It is possible, though, to return all the records from one of the tables using an outer JOIN clause. In MySQL, JOIN clauses are written as either LEFT JOIN or RIGHT JOIN.

A LEFT JOIN clause returns all the records from the “left” table and only the matching records from the right table. In the context of outer joins, the left table is the one referenced by the FROM clause, and the right table is any other table referenced after the JOIN statement.

Run the previous query again, but this time use a LEFT JOIN clause:

  • SELECT tourneys.name, tourneys.size, dinners.birthdate
  • FROM tourneys
  • LEFT JOIN dinners ON tourneys.name=dinners.name;

This command will return every record from the left table (in this case, tourneys) even if it doesn’t have a corresponding record in the right table. Any time there isn’t a matching record from the right table, it’s returned as NULL or just a blank value, depending on your RDBMS:

Output
+---------+------+------------+
| name    | size | birthdate  |
+---------+------+------------+
| Dolly   |  8.5 | 1946-01-19 |
| Etta    |    9 | 1938-01-25 |
| Irma    |    7 | 1941-02-18 |
| Barbara |  7.5 | 1948-12-25 |
| Gladys  |    8 | 1944-05-28 |
| Bettye  |    9 | NULL       |
+---------+------+------------+
6 rows in set (0.00 sec)

Now run the query again, this time with a RIGHT JOIN clause:

  • SELECT tourneys.name, tourneys.size, dinners.birthdate
  • FROM tourneys
  • RIGHT JOIN dinners ON tourneys.name=dinners.name;

This will return all the records from the right table (dinners). Because Lesley’s birthdate is recorded in the right table, but there is no corresponding row for her in the left table, the name and size columns will return as NULL values in that row:

Output
+---------+------+------------+
| name    | size | birthdate  |
+---------+------+------------+
| Dolly   |  8.5 | 1946-01-19 |
| Etta    |    9 | 1938-01-25 |
| Irma    |    7 | 1941-02-18 |
| Barbara |  7.5 | 1948-12-25 |
| Gladys  |    8 | 1944-05-28 |
| NULL    | NULL | 1946-05-02 |
+---------+------+------------+
6 rows in set (0.00 sec)

Note that left and right joins can be written as LEFT OUTER JOIN or RIGHT OUTER JOIN, although the OUTER part of the clause is implied. Likewise, specifying INNER JOIN will produce the same result as just writing JOIN.

As an alternative to using JOIN to query records from multiple tables, you can use the UNION clause.

ALSO READ  Bus conductor docked for allegedly stealing passenger’s phone

The UNION operator works slightly differently than a JOIN clause: instead of printing results from multiple tables as unique columns using a single SELECT statement, UNION combines the results of two SELECT statements into a single column.

To illustrate, run the following query:

  • SELECT name FROM tourneys UNION SELECT name FROM dinners;

This query will remove any duplicate entries, which is the default behavior of the UNION operator:

Output
+---------+
| name    |
+---------+
| Dolly   |
| Etta    |
| Irma    |
| Barbara |
| Gladys  |
| Bettye  |
| Lesley  |
+---------+
7 rows in set (0.00 sec)

To return all entries (including duplicates) use the UNION ALL operator:

  • SELECT name FROM tourneys UNION ALL SELECT name FROM dinners;
Output
+---------+
| name    |
+---------+
| Dolly   |
| Etta    |
| Irma    |
| Barbara |
| Gladys  |
| Bettye  |
| Dolly   |
| Etta    |
| Irma    |
| Barbara |
| Gladys  |
| Lesley  |
+---------+
12 rows in set (0.00 sec)

The names and number of the columns in the results table reflect the name and number of columns queried by the first SELECT statement. Note that when using UNION to query multiple columns from more than one table, each SELECT statement must query the same number of columns, the respective columns must have similar data types, and the columns in each SELECT statement must be in the same order. The following example shows what might result if you use a UNION clause on two SELECT statements that query a different number of columns:

  • SELECT name FROM dinners UNION SELECT name, wins FROM tourneys;
Output
ERROR 1222 (21000): The used SELECT statements have a different number of columns

Another way to query multiple tables is through the use of subqueries. Subqueries (also known as inner or nested queries) are queries enclosed within another query. These are useful in cases where you’re trying to filter the results of a query against the result of a separate aggregate function.

To illustrate this idea, say you want to know which of your friends have won more matches than Barbara. Rather than querying how many matches Barbara has won then running another query to see who has won more games than that, you can calculate both with a single query:

  • SELECT name, wins FROM tourneys
  • WHERE wins > (
  • SELECT wins FROM tourneys WHERE name = ‘Barbara’
  • );
Output
+--------+------+
| name   | wins |
+--------+------+
| Dolly  |    7 |
| Etta   |    4 |
| Irma   |    9 |
| Gladys |   13 |
+--------+------+
4 rows in set (0.00 sec)

The subquery in this statement was run only once; it only needed to find the value from the wins column in the same row as Barbara in the name column, and the data returned by the subquery and outer query are independent of one another. There are cases, though, where the outer query must first read every row in a table and compare those values against the data returned by the subquery in order to return the desired data. In this case, the subquery is referred to as a correlated subquery.

The following statement is an example of a correlated subquery. This query seeks to find which of your friends have won more games than is the average for those with the same shoe size:

  • SELECT name, size FROM tourneys AS t
  • WHERE wins > (
  • SELECT AVG(wins) FROM tourneys WHERE size = t.size
  • );

In order for the query to complete, it must first collect the name and size columns from the outer query. Then, it compares each row from that result set against the results of the inner query, which determines the average number of wins for individuals with identical shoe sizes. Because you only have two friends that have the same shoe size, there can only be one row in the result-set:

Output
+------+------+
| name | size |
+------+------+
| Etta |    9 |
+------+------+
1 row in set (0.00 sec)

As mentioned earlier, subqueries can be used to query results from multiple tables. To illustrate this with one final example, say you wanted to throw a surprise dinner for the group’s all-time best bowler. You could find which of your friends has the best bowling record and return their favorite meal with the following query:

  • SELECT name, entree, side, dessert
  • FROM dinners
  • WHERE name = (SELECT name FROM tourneys
  • WHERE wins = (SELECT MAX(wins) FROM tourneys));
Output
+--------+--------+-------+-----------+
| name   | entree | side  | dessert   |
+--------+--------+-------+-----------+
| Gladys | steak  | fries | ice cream |
+--------+--------+-------+-----------+
1 row in set (0.00 sec)

Notice that this statement not only includes a subquery, but also contains a subquery within that subquery.

Conclusion

Issuing queries is one of the most commonly-performed tasks within the realm of database management. There are a number of database administration tools, such as phpMyAdmin or pgAdmin, that allow you to perform queries and visualize the results, but issuing SELECT statements from the command line is still a widely-practiced workflow that can also provide you with greater control.

If you’re new to working with SQL, we encourage you to use our SQL Cheat Sheet as a reference and to review the official MySQL documentation. Additionally, if you’d like to learn more about SQL and relational databases, the following tutorials may be of interest to you:

392 thoughts on “An Introduction to Queries in MySQL

  1. Pingback: free sex chat
  2. Pingback: regles 421
  3. Pingback: cybersécurité
  4. Pingback: Raahe Guide
  5. Pingback: catskills hotel
  6. Pingback: megagame
  7. Pingback: evisa
  8. Pingback: 6mm arc ammo
  9. Pingback: itsMasum.Com
  10. Pingback: nangs Sydney
  11. Pingback: nangs sydney
  12. Pingback: website
  13. Pingback: itsmasum.com
  14. Pingback: random chat
  15. Pingback: boy chat
  16. Pingback: itsmasum.com
  17. Pingback: itsmasum.com
  18. Pingback: beijing jobs
  19. Pingback: live nude chat
  20. Pingback: live video chat
  21. Pingback: Kampus Islami
  22. Pingback: Kuliah Mudah
  23. Pingback: pg slot
  24. Pingback: 918kiss
  25. Pingback: ItMe.Xyz
  26. Pingback: FB URL Shortener
  27. Pingback: ItMe.Xyz
  28. Pingback: itme.xyz
  29. Pingback: MasumINTL.Com
  30. Pingback: itme.xyz
  31. Pingback: itme.xyz
  32. Pingback: mzplay
  33. Pingback: wix seo
  34. Pingback: satoshi t shirt
  35. Pingback: webcam girls
  36. Pingback: cheap sex webcams
  37. Pingback: cheap sex chat
  38. Pingback: free adult webcams
  39. Pingback: cheap sex webcams
  40. Pingback: texas heeler
  41. Pingback: houston tx salons
  42. Pingback: floodle
  43. Pingback: dog papers
  44. Pingback: clima en neza
  45. Pingback: linh hoang
  46. Pingback: Mitsubishi
  47. Pingback: live sex chat
  48. Pingback: cheap nude chat
  49. Pingback: cheap cam sex
  50. Pingback: cheap webcam sex
  51. Pingback: isla mujeres condo
  52. Pingback: play net app
  53. Pingback: dog yorkie mix
  54. Pingback: 라이브스코어
  55. Pingback: 스포츠중계
  56. Pingback: esports
  57. Pingback: french bulldog
  58. Pingback: aimbot xdefiant
  59. Pingback: vanguard mod
  60. Pingback: grey frenchies
  61. Pingback: alexa collins
  62. Pingback: 늑대닷컴
  63. Pingback: 늑대닷컴
  64. Pingback: chanel dog bowls
  65. Pingback: minnect expert
  66. Pingback: Dog Registry
  67. Pingback: Dog Registry
  68. Pingback: Dog Papers
  69. Pingback: Dog Papers
  70. Pingback: Dog Papers
  71. Pingback: Dog Registry
  72. Pingback: Dog Papers
  73. Pingback: french pitbull
  74. Pingback: clima tultitlán
  75. Pingback: magnolia bjj
  76. Pingback: golf cart rental
  77. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.

  78. Pingback: jadore cowboy
  79. Pingback: nepo hat
  80. Pingback: fartcoin crypto
  81. Pingback: joyce echols
  82. Pingback: clima cancun
  83. Pingback: micro bully
  84. Pingback: crypto
  85. Pingback: dog registry
  86. Hello, Neat post. There is an issue along with your web site in internet explorer, might check this? IE nonetheless is the marketplace chief and a huge part of other people will miss your magnificent writing due to this problem.

  87. Pingback: hairless bully
  88. Pingback: french doodles
  89. Asking questions are really good thing if you are not understanding anything fully, but this post presents nice understanding even.

  90. Wonderful post! I really enjoyed reading it. You’ve done a solid job presenting the topic. Can’t wait to more content like this in the future. Keep it up!

  91. Pingback: ragnarok servers
  92. Pingback: wix seo service
  93. I was suggested this blog by my cousin. I’m not sure whether this post is written by him as no one else know such detailed about my trouble. You are incredible! Thanks!

  94. Hello there, just became alert to your blog through Google, and found that it’s truly informative. I’m going to watch out for brussels. I’ll be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers!

  95. Hi there, just became aware of your blog through Google, and found that it’s truly informative. I am going to watch out for brussels. I’ll appreciate if you continue this in future. Many people will be benefited from your writing. Cheers!

  96. Hi there, just became aware of your blog through Google, and found that it’s truly informative. I’m gonna watch out for brussels. I’ll be grateful if you continue this in future. Many people will be benefited from your writing. Cheers!

  97. I personally find that i’ve been active for several months, mostly for cross-chain transfers, and it’s always stable performance. The updates are frequent and clear.

  98. Great website. Lots of useful information here. I am sending it to several buddies ans additionally sharing in delicious. And certainly, thank you on your effort!

  99. It is appropriate time to make some plans for the future and it’s time to be happy.
    I have read this post and if I could I desire to suggest you few interesting things or tips.

    Maybe you could write next articles referring to this
    article. I want to read even more things about it!

  100. First off I want to say great blog! I had a quick question in which I’d like to
    ask if you don’t mind. I was curious to know how you center yourself and clear your
    thoughts before writing. I’ve had trouble clearing my thoughts in getting my thoughts out.
    I do take pleasure in writing but it just
    seems like the first 10 to 15 minutes tend to be lost just trying to
    figure out how to begin. Any ideas or tips? Cheers!

  101. Do you mind if I quote a few of your posts as long as I provide credit and sources back to
    your weblog? My website is in the very same niche as yours and my visitors would genuinely benefit from some of
    the information you present here. Please let me know if this okay with you.
    Cheers!

  102. I’m not certain where you are getting your information, but great topic. I needs to spend a while finding out more or figuring out more. Thank you for great information I used to be looking for this information for my mission.

  103. I’m now not certain where you are getting your info, however great topic. I needs to spend a while learning much more or figuring out more. Thanks for magnificent info I was looking for this information for my mission.

  104. Hello! I just would like to offer you a big thumbs up for your excellent information you have got right here on this post. I will be returning to your site for more soon.

  105. An intriguing discussion is worth comment. I believe that you ought to write more on this topic, it might not be a taboo matter but usually people don’t speak about these topics. To the next! Best wishes!!

  106. A fascinating discussion is definitely worth comment. I believe that you need to publish more on this issue, it may not be a taboo subject but generally folks don’t talk about these topics. To the next! All the best!!

  107. An intriguing discussion is worth comment. I do believe that you need to publish more about this subject, it may not be a taboo subject but typically people don’t speak about these topics. To the next! All the best!!

  108. An interesting discussion is definitely worth comment. There’s no doubt that that you should publish more on this topic, it may not be a taboo subject but usually people do not talk about such subjects. To the next! All the best!!

  109. An interesting discussion is worth comment. There’s no doubt that that you ought to write more about this topic, it may not be a taboo matter but typically people do not speak about these topics. To the next! All the best!!

  110. An interesting discussion is worth comment. There’s no doubt that that you need to publish more about this subject, it might not be a taboo matter but typically people do not talk about such subjects. To the next! Many thanks!!

  111. An interesting discussion is definitely worth comment. I do think that you need to publish more on this subject matter, it may not be a taboo subject but generally folks don’t discuss such subjects. To the next! Best wishes!!

  112. A motivating discussion is worth comment. I do believe that you need to write more about this issue, it might not be a taboo subject but usually folks don’t discuss such issues. To the next! All the best!!

  113. An interesting discussion is definitely worth comment. I believe that you need to write more on this subject, it might not be a taboo subject but typically folks don’t talk about such subjects. To the next! Cheers!!

  114. A motivating discussion is worth comment. There’s no doubt that that you need to write more on this subject, it may not be a taboo subject but generally folks don’t discuss such subjects. To the next! Many thanks!!

  115. An intriguing discussion is definitely worth comment. I believe that you ought to publish more on this issue, it might not be a taboo matter but generally people don’t talk about these topics. To the next! Cheers!!

  116. A fascinating discussion is worth comment. There’s no doubt that that you ought to publish more about this issue, it might not be a taboo subject but usually people don’t talk about such subjects. To the next! Kind regards!!

  117. Hello there! This post could not be written any better! Looking through this article reminds me of my previous roommate! He always kept preaching about this. I’ll send this information to him. Fairly certain he will have a great read. Many thanks for sharing!

  118. Thank you a bunch for sharing this with all folks you really recognise what you are talking approximately! Bookmarked. Kindly additionally visit my web site =). We may have a hyperlink change agreement between us

  119. It’s actually a cool and helpful piece of info. I’m happy that you simply shared this useful information with us. Please keep us informed like this. Thanks for sharing.

  120. Hi there just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the same results.

  121. Pingback: live sex webcams
  122. Pingback: free sex shows
  123. Do you have a spam problem on this website; I also am a blogger, and I was wanting to know your situation; many of us have created some nice methods and we are looking to swap techniques with others, please shoot me an email if interested.

  124. great issues altogether, you just won a emblem new reader. What may you recommend about your put up that you just made some days in the past? Any sure?

  125. Great website. Lots of useful info here. I’m sending it to several friends ans additionally sharing in delicious. And certainly, thank you to your effort!

  126. What’s up i am kavin, its my first time to commenting anyplace, when i read this post i thought i could also make comment due to this sensible paragraph.

  127. Hello i am kavin, its my first time to commenting anyplace, when i read this paragraph i thought i could also make comment due to this sensible post.

  128. My partner and I stumbled over here coming from a different website and thought I might as well check things out. I like what I see so i am just following you. Look forward to looking at your web page repeatedly.

  129. Hey there! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no backup. Do you have any solutions to prevent hackers?

  130. I have fun with, cause I discovered just what I used to be having a look for. You’ve ended my 4 day long hunt! God Bless you man. Have a nice day. Bye

  131. Excellent way of explaining, and nice piece of writing to get information on the topic of my presentation topic, which i am going to convey in university.

  132. fantastic points altogether, you simply gained a new reader. What might you suggest in regards to your submit that you simply made a few days in the past? Any sure?

  133. Pingback: sex webcams
  134. Pingback: free sex shows
  135. Hello! This is kind of off topic but I need some help from an established blog. Is it very hard to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about making my own but I’m not sure where to begin. Do you have any ideas or suggestions? Cheers

  136. Hey there, I think your site might be having browser compatibility issues. When I look at your website in Firefox, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, excellent blog!

  137. Pingback: utc clock
  138. Pingback: cron timing tool
  139. Pingback: custom tron vanity
  140. Superb blog! Do you have any tips and hints for aspiring writers? I’m planning to start my own blog soon but I’m a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m completely overwhelmed .. Any ideas? Thanks!

  141. Hey there, I think your site might be having browser compatibility issues. When I look at your blog in Opera, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, great blog!

  142. Exceptional post however I was wondering if you could write a litte more on this subject? I’d be very thankful if you could elaborate a little bit further. Thanks!

  143. Good post. I learn something totally new and challenging on sites I stumbleupon everyday. It will always be useful to read articles from other writers and use something from other websites.

  144. I’m impressed, I must say. Seldom do I come across a blog that’s equally educative and entertaining, and without a doubt, you have hit the nail on the head. The problem is an issue that not enough men and women are speaking intelligently about. Now i’m very happy that I came across this in my search for something concerning this.

  145. Today, I went to the beach front with my kids. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is completely off topic but I had to tell someone!

  146. I was suggested this web site by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my difficulty. You’re incredible! Thanks!

  147. Greetings I am so happy I found your website, I really found you by accident, while I was browsing on Askjeeve for something else, Regardless I am here now and would just like to say kudos for a marvelous post and a all round entertaining blog (I also love the theme/design), I don’t have time to look over it all at the moment but I have saved it and also added your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the excellent work.

  148. Nice blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple adjustements would really make my blog stand out. Please let me know where you got your design. Thanks a lot

  149. Hello, I think your website may be having web browser compatibility issues. Whenever I take a look at your web site in Safari, it looks fine however, if opening in I.E., it’s got some overlapping issues. I just wanted to give you a quick heads up! Besides that, wonderful website!

  150. Pingback: kooky
  151. What i do not realize is in truth how you are not really a lot more smartly-favored than you may be now. You are very intelligent. You recognize thus considerably in terms of this matter, produced me in my view imagine it from a lot of varied angles. Its like men and women aren’t involved unless it’s something to do with Lady gaga! Your own stuffs excellent. All the time take care of it up!

  152. It’s really a nice and helpful piece of info. I’m glad that you simply shared this useful info with us. Please stay us up to date like this. Thank you for sharing.

  153. I’m really enjoying the theme/design of your site. Do you ever run into any web browser compatibility issues? A small number of my blog audience have complained about my website not operating correctly in Explorer but looks great in Opera. Do you have any suggestions to help fix this problem?

  154. I really love your website.. Very nice colors & theme. Did you build this site yourself? Please reply back as I’m planning to create my very own site and would like to know where you got this from or just what the theme is named. Thanks!

  155. When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks a lot!

  156. What’s Going down i’m new to this, I stumbled upon this I’ve discovered It positively helpful and it has helped me out loads. I’m hoping to give a contribution & help different customers like its helped me. Great job.

  157. I was curious if you ever thought of changing the structure of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 images. Maybe you could space it out better?

  158. whoah this weblog is excellent i like studying your articles. Keep up the good work! You recognize, a lot of persons are searching around for this information, you can help them greatly.

  159. Hello all, here every one is sharing such experience, so it’s pleasant to read this webpage, and I used to pay a visit this website daily.

  160. Hello there, I discovered your website by way of Google at the same time as searching for a similar subject, your site got here up, it seems to be great. I’ve bookmarked it in my google bookmarks

  161. Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how could we communicate?

  162. Great blog right here! Also your website so much up very fast! What host are you the use of? Can I get your affiliate hyperlink in your host? I desire my web site loaded up as quickly as yours lol

  163. I’ll immediately clutch your rss feed as I can’t to find your e-mail subscription hyperlink or e-newsletter service. Do you’ve any? Kindly permit me understand so that I may just subscribe. Thanks.

  164. Useful info. Lucky me I discovered your web site accidentally, and I’m shocked why this coincidence did not took place in advance! I bookmarked it.

  165. I am really impressed with your writing skills and also with the layout on your weblog. Is this a paid theme or did you modify it yourself? Either way keep up the nice quality writing, it’s rare to see a great blog like this one these days.

  166. certainly like your web site however you need to test the spelling on several of your posts. Several of them are rife with spelling problems and I find it very troublesome to inform the reality however I will certainly come again again.

  167. Hello to all, how is all, I think every one is getting more from this website, and your views are nice in support of new people.

  168. Wonderful goods from you, man. I have understand your stuff previous to and you’re just too excellent. I really like what you have acquired here, certainly like what you are stating and the way in which you say it. You make it entertaining and you still care for to keep it smart. I can not wait to read much more from you. This is actually a tremendous web site.

  169. Definitely believe that which you said. Your favourite reason appeared to be on the internet the easiest factor to take into account of. I say to you, I certainly get irked at the same time as people consider concerns that they just don’t recognise about. You controlled to hit the nail upon the highest and also defined out the whole thing without having side effect , other people could take a signal. Will likely be again to get more. Thanks

  170. Hi there! I know this is kinda off topic however I’d figured I’d ask. Would you be interested in exchanging links or maybe guest writing a blog post or vice-versa? My blog addresses a lot of the same topics as yours and I believe we could greatly benefit from each other. If you happen to be interested feel free to send me an email. I look forward to hearing from you! Superb blog by the way!

  171. Great post. I was checking constantly this blog and I’m impressed! Extremely helpful info specially the last part 🙂 I care for such information a lot. I was seeking this certain information for a very long time. Thank you and good luck.

  172. I have read several just right stuff here. Definitely value bookmarking for revisiting. I wonder how a lot attempt you place to create this sort of wonderful informative site.

  173. Excellent post. I was checking continuously this blog and I am impressed! Extremely useful info particularly the last part 🙂 I care for such info much. I was looking for this particular info for a long time. Thank you and best of luck.

  174. Pingback: WishHour.Com
  175. Pingback: WishHour.Com
  176. Pingback: WishHour.Com
  177. I’ve been browsing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. Personally, if all website owners and bloggers made good content as you did, the web will be a lot more useful than ever before.

  178. Hi my family member! I want to say that this article is awesome, great written and include approximately all significant infos. I’d like to see extra posts like this .

  179. Hey there, You’ve done an excellent job. I’ll definitely digg it and personally suggest to my friends. I’m confident they’ll be benefited from this site.

  180. I used to be recommended this blog by means of my cousin. I’m no longer sure whether this publish is written by way of him as no one else recognize such special approximately my trouble. You’re amazing! Thanks!

  181. Heya i’m for the first time here. I came across this board and I find It truly useful & it helped me out a lot. I hope to give something back and aid others like you aided me.

  182. A fascinating discussion is worth comment. I do think that you need to write more about this issue, it might not be a taboo matter but usually people do not speak about such issues. To the next! All the best!!

  183. I like the valuable info you provide in your articles. I’ll bookmark your blog and check again here frequently. I am quite sure I’ll learn lots of new stuff right here! Best of luck for the next!

  184. Great blog here! Also your web site loads up fast! What host are you using? Can I get your affiliate link to your host? I wish my web site loaded up as quickly as yours lol

  185. Hello there! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good success. If you know of any please share. Cheers!

  186. My brother suggested I might like this website. He was entirely right. This post actually made my day. You cann’t imagine just how much time I had spent for this info! Thanks!

  187. wonderful publish, very informative. I’m wondering why the opposite experts of this sector do not understand this. You must continue your writing. I’m sure, you have a great readers’ base already!

  188. Hello! This post couldn’t be written any better! Reading through this post reminds me of my old room mate! He always kept talking about this. I will forward this page to him. Pretty sure he will have a good read. Many thanks for sharing!

  189. I simply couldn’t go away your website before suggesting that I extremely enjoyed the usual information an individual provide to your visitors? Is gonna be back regularly in order to check out new posts

  190. Hi there! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done a outstanding job!

  191. It’s awesome to pay a visit this website and reading the views of all mates regarding this paragraph, while I am also eager of getting know-how.

  192. This is the perfect site for anybody who wishes to find out about this topic. You realize so much its almost tough to argue with you (not that I actually would want to…HaHa). You definitely put a brand new spin on a topic that’s been discussed for decades. Great stuff, just excellent!

  193. Magnificent beat ! I wish to apprentice while you amend your website, how could i subscribe for a blog website? The account helped me a acceptable deal. I had been tiny bit acquainted of this your broadcast provided bright clear concept

  194. I don’t even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you’re going to a famous blogger if you aren’t already 😉 Cheers!

  195. Nice post. I was checking constantly this blog and I’m inspired! Very useful information particularly the closing section 🙂 I handle such info a lot. I was seeking this certain info for a very lengthy time. Thanks and best of luck.

  196. Hey there, You’ve performed an excellent job. I’ll certainly digg it and for my part suggest to my friends. I am confident they will be benefited from this site.

  197. Hello there, You’ve done a great job. I’ll definitely digg it and for my part suggest to my friends. I am confident they’ll be benefited from this web site.

  198. The other day, while I was at work, my cousin stole my iphone and tested to see if it can survive a forty foot drop, just so she can be a youtube sensation. My apple ipad is now destroyed and she has 83 views. I know this is totally off topic but I had to share it with someone!

  199. I’m truly enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a designer to create your theme? Fantastic work!

  200. Yesterday, while I was at work, my cousin stole my iphone and tested to see if it can survive a 30 foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is entirely off topic but I had to share it with someone!

  201. Appreciating the persistence you put into your blog and in depth information you present. It’s nice to come across a blog every once in a while that isn’t the same outdated rehashed material. Excellent read! I’ve bookmarked your site and I’m adding your RSS feeds to my Google account.

  202. Great site. Lots of useful information here. I’m sending it to some buddies ans additionally sharing in delicious. And obviously, thanks on your effort!

  203. constantly i used to read smaller articles which as well clear their motive, and that is also happening with this article which I am reading at this place.

  204. You really make it seem really easy together with your presentation however I in finding this topic to be actually one thing that I think I might by no means understand. It kind of feels too complicated and very wide for me. I’m taking a look ahead on your subsequent post, I’ll attempt to get the cling of it!

  205. Thank you, I have just been looking for info approximately this subject for ages and yours is the best I have discovered till now. However, what concerning the bottom line? Are you sure about the supply?

  206. Hello, Neat post. There’s an issue along with your web site in web explorer, could test this? IE nonetheless is the marketplace chief and a good element of other people will miss your fantastic writing due to this problem.

  207. Aw, this was a really good post. Spending some time and actual effort to make a great article… but what can I say… I procrastinate a lot and never manage to get anything done.

Leave a Reply

Your email address will not be published. Required fields are marked *