大家好是有可能重寫查詢:重寫子查詢(不)作爲加入
select userid from User where userid not in(select userid from UserRole where roleid in(8));
的加入?
問題是,一個用戶可能有幾個角色
謝謝你提前。
mysql> desc User; +--------------------+-------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------------+-------------------+------+-----+---------+----------------+ | userId | int(11) | NO | PRI | NULL | auto_increment | | userName | varchar(50) | YES | | NULL | |
...等用戶相關的列
mysql> desc UserRole; +--------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+---------+------+-----+---------+-------+ | userId | int(11) | NO | PRI | 0 | | | roleId | int(11) | NO | PRI | 0 | | +--------+---------+------+-----+---------+-------+
我聞到作業... – cletus 2009-01-05 11:22:38