Subqueries: The Juicy Bits

People love to know where all the juicy stuff is in the bible. So how about we create a table which points in the right direction? Note the use of the SET data type, on one of its rare outings.

DROP TABLE IF EXISTS juicybits;

CREATE TABLE juicybits(
  book        VARCHAR(32),
  cap         TINYINT UNSIGNED,
  verse_start TINYINT UNSIGNED,
  verse_end   TINYINT UNSIGNED,
  title       VARCHAR(255) NOT NULL,
  class       SET('prostitution','virgin',  
                  'insults','rape','slavery',
                  'willy','bear-maul','stoning')
);

Procedures: One Chapter at a Time

Stored Procedures and Functions are a biggy on the MySQL Developer exam. They account for 20% of the marks of the second paper. And no wonder, there's a lot of new functionality (and syntax) to keep in mind. So with that in mind, let's put a procedure together.

Suppose you want to see the all of Genesis Cap 1 together. We can use group_concat() to squidge all the verses in Genesis 1 together on one line.

SELECT GROUP_CONCAT(line  ORDER BY verse SEPARATOR ' ')  as genesis
  FROM bible
 WHERE book = 'Ge'
   AND cap = 1 \G

Holy S-Q-L !

MySQL 5 Features

Once you have your bible database up and running, there are lots of fun queries you can try. Each page focuses on a different area of SQL. Provided you've installed the biblesql database, you should be able to cut and paste the queries from the pages below straight into your mysql browser.

Syndicate content