|
|
|
|
CREATE TABLE ".MPREFIX."transactions (
`transactions_id` int(10) unsigned NOT NULL auto_increment,
`transactions_num` int(7) unsigned NOT NULL default '1',
`transactions_name` varchar(128) NOT NULL default '',
`transactions_type` tinyint(1) default NULL,
PRIMARY KEY (transactions_id)
) TYPE=MyISAM;
CREATE TABLE ".MPREFIX."transactions_inst (
`inst_id` int(10) unsigned NOT NULL auto_increment,
`inst_transactions_id` int(10) unsigned NOT NULL default '0',
`inst_decision` text,
`inst_term` varchar(128) NOT NULL default '',
`inst_result` tinyint(1) unsigned NOT NULL default '1',
PRIMARY KEY (inst_id)
) TYPE=MyISAM;,
CREATE TABLE ".MPREFIX."transactions_inst_to_user (
`inst_to_id` int(10) unsigned NOT NULL auto_increment,
`inst_to_inst_id` int(10) unsigned NOT NULL default '0',
`inst_to_user_id` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (inst_to_id)
) TYPE=MyISAM;,
CREATE TABLE ".MPREFIX."transactions_user (
`Id` int(6) unsigned NOT NULL auto_increment,
`name` varchar(128) NOT NULL default '',
`email` varchar(128) NOT NULL default '',
`priority` int(2) unsigned NOT NULL default '1',
PRIMARY KEY (`Id`)
) ENGINE=MyISAM;
transactions.transactions_id = transactions_inst.inst_transactions_id Как 1:*
transactions_inst.inst_id = transactions_inst_to_user.inst_to_inst_id Как 1:*
transactions_inst.inst_to_user_id = transactions_user.Id Как 1:*
SELECT * FROM transactions_inst WHERE inst_transactions_id="Какое-то значение"
|
Затем в цикле
SELECT iuser.name
FROM transactions_inst_to_user as ito_user
LEFT JOIN transactions_user as iuser
ON ito_user.inst_to_user_id=iuser.Id
WHERE ito_user.inst_to_inst_id="Значение которое будет от 1 запроса['inst_id']";
|
Получается очень много запросов, можно ли сделать это в один запрос, чтобы не приходилось в цикле выполнять второй?
Протокол соединяется 1 ко * c Поручениями и каждому поручению соответствует от 1 до * Ответственных.
Нужно получить по определенному протоколу все поручения и для каждого поручения ответственных.
№ Поручения | Ответственные | Текст поручения | Срок | Результат | | |
|
|