我有三张桌子
让我们一个demo_organization ;
+--------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| org_name | varchar(100) | NO | | NULL | |
| org_type | varchar(100) | NO | | NULL | |
| abn_acn_no | varchar(100) | NO | | NULL | |
| org_url | varchar(120) | NO | | NULL | |
| notes | longtext | NO | | NULL | |
| city | varchar(100) | YES | | NULL | |
第二个是demo_user
mysql> desc demo_user ;
+--------------------+----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+----------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_name | varchar(100) | NO | | NULL | |
| first_name | varchar(100) | NO | | NULL | |
| middle_name | varchar(100) | NO | | NULL | |
| last_name | varchar(100) | NO | | NULL | |
| image | varchar(10000) | YES | | NULL | |
| password | varchar(80) | NO | | NULL | |
| role | varchar(20) | NO | | NULL | |
| org_name_id | int(11) | NO | MUL | NULL | |
| timezone_id | int(11) | NO | MUL | NULL | |
第三个是demo_meeting;
外观
mysql> desc demo_meeting ;
+--------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(200) | NO | | NULL | |
| meetingID | varchar(50) | NO | | NULL | |
| venue_id | int(11) | YES | MUL | NULL | |
| status | int(11) | YES | | NULL | |
| recurring_time | varchar(50) | NO | | NULL | |
| attendee_passwd | varchar(100) | NO | | NULL | |
| moderator_passwd | varchar(100) | NO | | NULL | |
| date_created | datetime | NO | | NULL | |
| start_time | varchar(100) | NO | | NULL | |
| end_time | varchar(100) | NO | | NULL | |
| meeting_duration | varchar(100) | NO | | NULL | |
| meeting_datetime | datetime | YES | | NULL | |
| timezone | varchar(50) | NO | | NULL | |
| reminder | tinyint(1) | NO | | NULL | |
| duration | varchar(20) | NO | | NULL | |
| created_by_id | int(11) | NO | MUL | NULL | |
第三张表中created_by_id指的是demo_user表的A用户(外键)
而 org_name_id(demo_user table ) 指的是 demo_organization (demo_organization table 的外键)
更新
mysql> desc demo_meetingroom;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(100) | NO | | NULL | |
| type | varchar(200) | NO | | NULL | |
| expired_on | varchar(100) | NO | | NULL | |
| user_id | int(11) | YES | MUL | NULL | |
+------------+--------------+------+-----+---------+----------------+
现在我正在尝试为特定组织安排所有会议。
我正在写一个查询
select meetingID ,type from demo_meeting as dm ,demo_meetingroom as dmr
Where venue_id IS NOT NULL
and dm.name = dmr.name
AND created_by_id IN
(
SELECT id from demo_user WHERE org_name_id IN
(
SELECT id from demo_organization where id =
(SELECT org_name_id from demo_user WHERE user_name = 'God')
)
);
不幸的是它返回给我空集(但有价值)
请帮我看看我做错了什么?