Month: April 2007

  • Access Control Quiz

    First, the setup:

    CREATE TABLE `user` (
      `user` varchar(255) DEFAULT NULL,
      `host` varchar(255) DEFAULT NULL,
      `sort` int(11) DEFAULT NULL
    );
    
    INSERT INTO `user` 
        (`user`, `host`, `sort`) 
    VALUES 
        ('','%',8),
        ('testUser','%',7),
        ('','%localhost',9),
        ('testUser','%localhost',5),
        ('','%localhost%',10),
        ('testUser','%localhost%',6),
        ('','localhost',2),
        ('testUser','localhost',1),
        ('','localhost%',4),
        ('testUser','localhost%',3);

    Now, the quiz:

    SELECT * FROM user ORDER BY ___

    Fill in the blank to get the following output. Difficulty: the `sort` field may not appear anywhere in the query.

    +----------+-------------+------+
    | user     | host        | sort |
    +----------+-------------+------+
    | testUser | localhost   |    1 |
    |          | localhost   |    2 |
    | testUser | localhost%  |    3 |
    |          | localhost%  |    4 |
    | testUser | %localhost  |    5 |
    | testUser | %localhost% |    6 |
    | testUser | %           |    7 |
    |          | %           |    8 |
    |          | %localhost  |    9 |
    |          | %localhost% |   10 |
    +----------+-------------+------+