mysql>
describe employee;+--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | LastName | varchar(25) | YES | UNI | NULL | | | DepartmentID | int(4) | YES | | NULL | | +--------------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> select * from employee;
+-----------+--------------+
| LastName | DepartmentID |
+-----------+--------------+
| Rafferty | 31 |
| Jones | 33 |
| Steinberg | 33 |
| Robinson | 34 |
| Smith | 34 |
| John | NULL |
+-----------+--------------+
6 rows in set (0.01 sec)
mysql> select t1.* from (SELECT * FROM employee WHERE DepartmentID > 32) AS t1 WHERE t1.DepartmentID < 34;
+-----------+--------------+
| LastName | DepartmentID |
+-----------+--------------+
| Jones | 33 |
| Steinberg | 33 |
+-----------+--------------+
2 rows in set (0.00 sec)
Note: If inner table (generated by the inner select) has no alias, this error is returned:
mysql> select * from (SELECT * FROM employee WHERE DepartmentID > 32);
ERROR 1248 (42000): Every derived table must have its own alias
No comments:
Post a Comment