1

我正在使用旧数据库创建一个新系统,需要一些帮助(因为缺乏经验) 这可能过于复杂,但这就是数据库的设置方式,我无法更改它。

有3张桌子。会话 1、会话 2 和注册人。

Session 1 和 Session 2 除了内容是一样的。所以它的工作原理是,如果一个人想在特定日期预订会话 1 和会话 2,数据库将在会话 1 和会话 2 的“id”行中插入“5”。'id' 是主索引。

“注册人”中有 2 行包含一个列表(例如 5、6、7),其中包含注册人姓名和在会话 1 和会话 2 中找到的一些 id。因此,如果您想知道该人是否预订会话 1,会话的 id 将在注册人会话 1 列表中。

就像我说的。复杂。

我可以毫无困难地进行单独的查询

SELECT * FROM Session_1 WHERE id IN ($registrant_session_1 /* This is a single quote implode for the ouput of registrant_session_1 */ )"

SELECT * FROM Session_2 WHERE id IN ($registrant_session_2 /* This is a single quote implode for the ouput of registrant_session_2 */)

我需要帮助创建一个将它们连接起来以同时输出的查询。所以理论是我首先进行会话检查,然后根据 id 加入它们。

4

2 回答 2

0

也许您可以使用“联合”子句 FROM Session_1 WHERE Session_1.id IN ($registrant_session_1 /* This is a single quote implode for the ouput of registrant_session_1 */ ) UNION (SELECT * FROM Session_2 WHERE Session_2.id IN ($registrant_session_2 /* This is a single quote implode for the ouput of registrant_session_2 */)

于 2012-08-10T12:49:45.870 回答
0

这是我第一次学习 MySQL 时发现的一个特别有用的网站http://www.tizag.com/mysqlTutorial/mysqljoins.php

于 2012-08-10T12:51:14.467 回答