运行查询的查询我有一个表,看起来像这样:在MySQL
+-----+--------------+---------+----------+---------------------+---------------------+ | id | username | case_id | status | date_assigned | date_removed | +-----+--------------+---------+----------+---------------------+---------------------+ | 21 | hemcreynolds | 802 | inactive | 2007-08-20 07:15:48 | 2008-04-15 16:08:54 | | 133 | licox | 868 | active | 2007-09-02 11:55:37 | 0000-00-00 00:00:00 | | 3 | kashepherd | 794 | inactive | 2007-08-17 13:54:39 | 2010-08-12 14:40:37 | | 4 | tithomas | 795 | active | 2007-08-17 13:56:06 | 0000-00-00 00:00:00 | | 5 | stcosse | 795 | inactive | 2007-08-17 13:56:26 | 2007-09-25 10:02:03 | | 6 | mefong yit | 914 | active | 2007-08-17 14:00:29 | 0000-00-00 00:00:00 | | 7 | tamouledoux | 842 | active | 2007-08-17 14:09:16 | 0000-00-00 00:00:00 | | 9 | chgross | 903 | active | 2007-08-18 08:38:38 | 0000-00-00 00:00:00 | | 20 | ticrane | 802 | inactive | 2007-08-20 07:15:41 | 2008-04-15 16:44:35 | | 19 | hemcreynolds | 818 | inactive | 2007-08-20 07:15:12 | 2008-04-15 16:08:57 | +-----+--------------+---------+----------+---------------------+---------------------+
我想运行一个查询发现该情况下,用户已经被分配给用户名,例如
话,我想找到全部分配到案件的其他用户,我的用户(ticrane)被分配到:
SELECT * FROM assignements WHERE case_id = (all of the case ids generated by the previous query)
我想这样做在一个单一的查询。我想像某种连接是为了这里,但我不认为你可以加入来自同一个表的结果。困惑。有什么建议么?
去自加入 – 2012-03-28 11:17:07