Module 4: Basic Reporting


1.  

What is the command to list all the data in the monsters table?

2.  

What is the command to list only the records with the values "vampire" and "werewolf" in the m_types field of the monsters table?

3.  

What does the following command do?

 SELECT m_types FROM monsters LIMIT 13; 

4.  

How do you view the records for the m_active field in the monsters table, starting with record 9 and listing the next 13 records?

5.  

How do you list each unique entry in the m_types field of the monsters table?

6.  

What is the code for listing the m_names , m_types , and m_active fields in the monsters table, using the headers Monster Names , Kind of Monster, and Day/Night/Both, respectively.

7.  

What are the two types of operators used for comparisons in the WHERE clause?

8.  

What are the four basic commands for viewing databases and tables?

9.  

What are two different ways that a WHERE clause could specify a numeric range of data between 42 and 113 in the field some_number ?

10.  

How can you display entire records from the monsters table that contain "vampire" in the m_types field and a name beginning with the letter D in the m_names field?

11.  

How do you list m_numbers and m_names fields of every instance in the monsters table where you know the m_creators field should read "Joss" but due to a typo, the m_creators entry is not capitalized?

Answers

1.  

The correct code is:

 SELECT * FROM monsters; 

2.  

The correct code is:

 SELECT * FROM monsters WHERE m_types="vampire" AND m_types="werewolf"; 

3.  

It lists the contents of the m_types column for the first 13 records in the monster table.

4.  

The simplest correct code is:

 SELECT m_active FROM monsters LIMIT 8,13; 

5.  

The simplest correct code is:

 SELECT DISTINCT m_types FROM monsters; 

6.  

The code for such a list is:

 SELECT m_names AS "Monster Names", m_types AS "Kind of Monster",  m_active as "Day/Night/Both" FROM monsters; 

7.  

The two types of operators used for comparison in WHERE clauses are arithmetic and logical.

8.  

The four most basic commands to view databases and tables are:

 SHOW DATABASES; USE <  database_name  >; SHOW TABLES; DESC <  table_name  >; 

9.  

The range can be specified in a WHERE clause any of the following ways:

 WHERE some_number>=42 AND some_number<=113; WHERE some_number BETWEEN 42 AND 113; WHERE some_number >41 and <114; 

10.  

Use the following code:

 SELECT * FROM monsters WHERE m_types="vampire" AND m_names LIKE "D%"; 

11.  

Use the following code:

 SELECT m_numbers, m_names FROM monsters WHERE BINARY m_creators="joss"; 



MySQL(c) Essential Skills
MySQL: Essential Skills
ISBN: 0072255137
EAN: 2147483647
Year: 2006
Pages: 109

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net