Getting Information About Databases and Tables There are several things to note about this query: The query uses an  INNER JOIN  to combine the tables. An  INNER JOIN  permits rows from either table to appear in the result if and only if both tables meet the conditions specified in the  ON  clause. In this example, the  ON  clause specifies that the  name  column in the  pet  table must match the  name  column in the  event  table. If a name appears in one table but not the other, the row does not appear in the result because the condition in the  ON  clause fails. •The  FROM  clause joins two tables because the query needs to pull information from both of them. •When combining (joining) information from multiple tables, you need to specify how records in one table can be matched to records in the other. This is easy because they both have a  name  column. The query uses an  ON  clause to match up records in the two tables based on the  name  values. •Because the  name  column occurs in both tables, you must be specific about which table you mean when referring to the column. This is done by prepending the table name to the column name. You need not have two different tables to perform a join. Sometimes it is useful to join a table to itself, if you want to compare records in a table to other records in that same table. For example, to find breeding pairs among your pets, you can join the  pet  table with itself to produce candidate pairs of live males and females of like species: In this query, we specify aliases for the table name to refer to the columns and keep straight which instance of the table each column reference is associated with. FROM pet INNER JOIN event ON pet.name = event.name WHERE event.type = ’litter’; +--------+------+-----------------------------+ | name | age | remark | +--------+------+-----------------------------+ | Fluffy | 2 | 4 kittens, 3 female, 1 male | | Buffy | 4 | 5 puppies, 2 female, 3 male | | Buffy | 5 | 3 puppies, 3 female | +--------+------+-----------------------------+ mysql>  SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species FROM pet AS p1 INNER JOIN pet AS p2 ON p1.species = p2.species AND p1.sex = ’f’ AND p1.death IS NULL AND p2.sex = ’m’ AND p2.death IS NULL; +--------+------+-------+------+---------+ | name | sex | name | sex | species | +--------+------+-------+------+---------+ | Fluffy | f | Claws | m | cat | | Buffy | f | Fang | m | dog | +--------+------+-------+------+---------+ 3.4 Getting Information About Databases and Tables What if you forget the name of a database or table, or what the structure of a given table is (for example, what its columns are called)? MySQL addresses this problem through several statements that provide information about the databases and tables it supports. You have previously seen  SHOW DATABASES , which lists the databases managed by the server. To find out which database is currently selected, use the  DATABASE()  function: mysql>  SELECT DATABASE(); +------------+ | DATABASE() | 325